I could use some assistance with identifying my error in my expression within my app. My expression (see below) is not causing an error rather, it is not working correctly. I am entering the expression into Question11 of the VPRAITbl, ValidIf option.
IF(IN(LOOKUP(maxrow(VPRAITbl, VPRAIDateEntered, [ID] = [_thisrow].[ID]), CrimeHistoryTbl, ID, OffenseInfo), LIST(โJuvenileโ)), LIST(True), LIST(false))
I think the problem is that I am incorrectly using the โMAXROWโ. When I have tried to use a similar expression only using the IF(IN(LOOKUP portion, I begin to get errors. Basically, if the client has past conviction in the CrimeHistoryTbl in the Offenseinfo field (EnumList) that are indicated to be โJuvenileโ offenses, then Question11 (Enum) of the VPRAITbl has to be true, else false. I have entered a test client with generic information and given him a โJuvenileโ offense, but the results of the expression is false. I think my use of MAXROW is only looking at the last entry or only one of several entries. A person can have multiple previous convictions and if any or many of them are indicated to be โJuvenileโ then Question11 must be true.
Your assistance is much appreciated!
Solved! Go to Solution.
Wow! I now realize that I made a number of mistakes. I am beginning to see that Iโm in way over my head. Thank you for all your help with this. Let me try to explain how I ended up here. The App that I am currently working on is version 2 of the one we have been using for last 18 or so months. After using the previous version for some time, we learned that we were capturing a bunch of useless data and that the structure of the App was poor and not condusive to generating a Word document report for court without a huge amount of leg work. I created a new version (the one Iโm currently working on) and have made numerous changes. One of the things that I failed to do was to remove the =uniqueID from each of the child tables to the Courttbl. Some had been removed and when I created the diagram above, I did not check each before creating it and assumed that =uniquedID was there for each. Luckily, there is only one record in each of these child tables and despite the fact that the =uniqueID was present, the App did grab the correct ID from the CourtTbl, i.e. CourtID.
I have since taken the table structure advice of Dave (see below) and have updated all child tables to the CourtTbl and the references. I have also updated all of the expressions, mostly in the VPRAITbl to reflect the correct column name, i.e. CourtID
As for Question11, I started with Steveโs suggested expression and made some changes to reflect the changes to the table structure (see below).
ISNOTBLANK(FILTER(โCrimeHistoryTblโ,AND(([CourtID] = [_THISROW].[CourtID]),IN(โJuvenileโ,[OffenseInfo]))))
Long story short, the expression for Question11 is now working correctly, which is GREAT, THANK YOU! The down side is that I am not done.
Again, THANK YOU for all your help, I appreciate all the user of the app sheet community coming to my rescue.
Thatโs exactly what MAXROW() does: it finds the one row of a table that has the highest value in a given column. Your use:
maxrow(VPRAITbl, VPRAIDateEntered, [ID] = [_thisrow].[ID])
says, โgive me the row in the VPRAITbl table having the highest value in the VPRAIDateEntered column, considering only those rows where the ID column value matches the ID column value of this form.โ Or, put more simply, โgive me the VPRAITbl entry with the newest VPRAIDateEntered for this ID.โ
What is the goal you are using MAXROW() to try to achieve?
Iโm curious why youโre asking the app user to supply an answer that the app can answer itself? And limiting the user to only providing the answer the app itself has already chosen? Why ask the user at all?
Thank you for your assistance! I do believe that I should not be using MAXROW and am struggling with how to re-write the expression using IF(IN(LOOKUP. The goal in the VPRAITbl, Question11โs expression would be to scan all of the records in the CrimeHistoryTbl, OffenseInfo field that belong to this client and if one of those records in the OffenseInfo field (EnumList) indicates โJuvenileโ then make Question11 โTrueโ.
I agree with your question, If โJuvenileโ is a part of one of the CrimeHistoryTbl records, then it is true and it would be great if this was just automatically selected and the user did not have to do so. If it is not True, then it is False and be automatically selected accordingly. I am assuming that using ValidIf is also incorrect in this example?
If I re-write this to:
IF(IN(LOOKUP(VPRAITbl, VPRAIDateEntered, [ID] = [_thisrow].[ID]), CrimeHistoryTbl, ID, OffenseInfo)), LIST(โJuvenileโ)), LIST(True), LIST(false))
I get an error (see below) and cannot tell where I am placing an incorrect parentheses.
Expression โIF(IN(LOOKUP(VPRAITbl, VPRAIDateEntered, [ID] = [_thisrow].[ID]), CrimeHistoryTbl, ID, OffenseInfo)), LIST(โJuvenileโ)), LIST(True), LIST(false))โ could not be parsed due to exception: Number of opened and closed parentheses does not match.
What are your thought or even if this is somewhere near correct? Thank you again!
Well the expression is all kinds of broken. You have too many closing parenthesis.
LOOKUP(find-value, in-dataset, in-column, return-column)
You only have three arguments.
IN(match-value, in-list)
You have have four arguments.
I also feel like you should be doing this as a regular app formula for the column rather than a Valid_If.
Ah! More insight! So this:
MAXROW(
"VPRAITbl",
"VPRAIDateEntered",
([ID] = [_THISROW].[ID])
)
Iโm guessing is an attempt to get the ID column value from the VPRAITbl entry the user is in the process of entering? If so, it would seem to be entirely unneeded and could be replaced entirely with:
[_THISROW].[ID]
Yes, just [_THISROW].[ID]
, since that already refers to the value of the ID column of the row currently in the form, which will be a row in the VPRAITbl table. If that guess is correct, we can simplify your original expression:
IF(
IN(
LOOKUP(
[_THISROW].[ID],
"CrimeHistoryTbl",
"ID",
"OffenseInfo"
),
LIST(โJuvenileโ)
),
LIST(TRUE),
LIST(FALSE)
)
LOOKUP() finds only the first matching row, but you said there may be multiple rows in CrimeHistoryTbl for any given ID value, so LOOKUP() may not provide all needed information (as youโve noticed). So you need a better way. Hereโs my suggestion, again assuming that the ID column value in VPRAITbl and CrimeHistoryTbl have the same meaning:
ISNOTBLANK(
FILTER(
"CrimeHistoryTbl",
AND(
([ID] = [_THISROW].[ID]),
IN(โJuvenileโ, [OffenseInfo])
)
)
)
FILTER("CrimeHistoryTbl", AND(..., ...))
finds all rows in CrimeHistoryTbl that match both of the given criteria (AND(..., ...)
; see (2) & (3)).
([ID] = [_THISROW].[ID])
matches only those rows in CrimeHistoryTbl with an ID column value that matches the ID column value of the form. This answers the question, โdoes this CrimeHistoryTbl row correspond to the person identified in the VPRAITbl row in the form?โ
IN(โJuvenileโ, [OffenseInfo])
matches only if the EnumList in the OffenseInfo column of the row in the CrimeHistoryTbl table contains a Juvenile entry. This answers the question, โdoes this CrimeHistoryTbl row describe someone with a Juvenile offense?โ
ISNOTBLANK(...)
answers the question, โwere any matching rows found?โ
This expression could be used as the initial value expression for Question11, eliminating the need for a Valid If expression altogether.
Hello, and again thank you for all the help. I tried the expression below and while it does not get any error messages, it does not work correctly.
When I look at the explanation of the expression in the app (see below), I think I see the problem, but am unsure how to fix it. I have Bold the piece that i think is causing the problem.
ISNOTBLANK(
โฆThe list of values of column 'CrimeIDโ
โฆfrom rows of table โCrimeHistoryTblโ
โฆwhere this condition is true: (ALL these statements are true:
โฆ1: (The value of column โIDโ) is equal to (The value of โIDโ from the row referenced by โIDโ)
โฆ2: (โJuvenileโ) is one of the values in the list (The value of column โOffenseInfoโ)))
โโฆThe list values of columnโ should be โIDโ not CrimeID. There is a CrimeID field in the CrimeHistoryTbl, but it is only there to allow for a one to many relationship to the ClientTbl which is the Parent Table.
The ClientTbl is the parent to the CrimeHistorytbl (one to many relationship) and they REF each other via the field โIDโ. The CrimeHistoryTbl as a second field labeled CrimeID using =uniqueID just to allow for multiple entries under the same ID.
I hope Iโm making sense. Thank you again.
That actually shouldnโt matter, since the expression isnโt concerned with the meaning of the values, but merely that values are returned or not.
Iโm more inclined to suspect I misunderstood the meanings of the ID columns in the CrimeHistoryTbl and VPRAITbl tables. Can you explain the meanings of those two columns?
Thank you for taking so much time with this!
The โIDโ Field/column in both the VPRAITbl and CrimeHistoryTbl is what I would call the โPrimary Keyโ. the Unique identifier for each record. I created a diagram of the APPโs table structure if it helps.
When I try to use the IF(IN(LookUP expression you wrote, I get the following error message:
Column Name โQuestion11โ in Schema โVPRAITbl_Schemaโ of Column Type โYes/Noโ has an invalid โInitial Valueโ of โ=IF( IN( LOOKUP( [_THISROW].[ID], โCrimeHistoryTblโ, โIDโ, โOffenseInfoโ ), LIST(โJuvenileโ) ), LIST(TRUE), LIST(FALSE) )โ. The type of the Initial Value does not match the column type. Consider using โโ instead.
To be honest, Iโm a bit twisted around on this and donโt know where to go from here. What are youโre thoughts? Thanks for everything!
Youโre diagram doesnโt make sense to me. If all of the ID columns have their own UNIQUEID() values, there are no relationships.
As for the initial value expression, try using the second expression I gave above:
ISNOTBLANK(
FILTER(
"CrimeHistoryTbl",
AND(
([ID] = [_THISROW].[ID]),
IN(โJuvenileโ, [OffenseInfo])
)
)
)
I think I understand your diagramโฆ
So first, Iโm going to go through the way I think your data should be setup.
ResidenceTbl, EmploymentTbl, SocialInfoTbl, SupervisionTbl, VPRAITbl, and DALETbl all have a column named CourtID (that will help keep the associated IDs together). This column should be a Ref column and they should all point to the CourtTbl and have matching values itโs CourtID.
CourtTbl and CrimeHistoryTbl both have a column named ID and is a Ref column pointing to ClientTbl. ClientTblโs ID column should be a regular type of field (text, number, etc.).
Assuming we are still trying to solve the original issue ofโฆ
โฆthen you should set the column formula to beโฆ
If the data is setup correctly, the above should work no problemo. However, I also parrot Steveโs thought about the โ=uniqueIDโ you have shown for each one in the diagram. Each field isnโt generating itโs own uniqueID separatelyโฆright?
Wow! I now realize that I made a number of mistakes. I am beginning to see that Iโm in way over my head. Thank you for all your help with this. Let me try to explain how I ended up here. The App that I am currently working on is version 2 of the one we have been using for last 18 or so months. After using the previous version for some time, we learned that we were capturing a bunch of useless data and that the structure of the App was poor and not condusive to generating a Word document report for court without a huge amount of leg work. I created a new version (the one Iโm currently working on) and have made numerous changes. One of the things that I failed to do was to remove the =uniqueID from each of the child tables to the Courttbl. Some had been removed and when I created the diagram above, I did not check each before creating it and assumed that =uniquedID was there for each. Luckily, there is only one record in each of these child tables and despite the fact that the =uniqueID was present, the App did grab the correct ID from the CourtTbl, i.e. CourtID.
I have since taken the table structure advice of Dave (see below) and have updated all child tables to the CourtTbl and the references. I have also updated all of the expressions, mostly in the VPRAITbl to reflect the correct column name, i.e. CourtID
As for Question11, I started with Steveโs suggested expression and made some changes to reflect the changes to the table structure (see below).
ISNOTBLANK(FILTER(โCrimeHistoryTblโ,AND(([CourtID] = [_THISROW].[CourtID]),IN(โJuvenileโ,[OffenseInfo]))))
Long story short, the expression for Question11 is now working correctly, which is GREAT, THANK YOU! The down side is that I am not done.
Again, THANK YOU for all your help, I appreciate all the user of the app sheet community coming to my rescue.
User | Count |
---|---|
39 | |
28 | |
23 | |
23 | |
13 |