Hello. I have a parent table called “Work Orders.” I have a child table called “Work Order Comments.”
I want to view only the most recent entry in the work order comments related to a work order.
I created a virtual column in the parent table with a deref to the child table (via ref row called “Comments”). Looks like this:
[Comments][Comments]
This works great except it compiles all of the comments related to that work order. Is there a way to only select/view the most recent entry via a deref or is this only possible via a SELECT expression?
You need a second column as an intermediate step in order to use the ref_rows. 1st column: ORDERBY( [Comments][key-column] , [timestamp] , true ). 2nd column: [1st-col].[comments]
Otherwise, LOOKUP(MAXROW()) will get you there with one column/expression, but could be a lot less efficient if you have lots of records.
EDIT: forgot the ANY() in above crossed-out portion.
1st should be Ref, 2nd should be same as the [comments] column, probably Text. The VC auto-chose the type from the initial, incorrect, expression, so now they need changed.
The expression worked but it was only pulling the very last comment from the entire table and “duplicating” that across all the work orders (hard to explain).
I tried several variations and this one seemed to work:
That issue suggests that your [Comments] is not actually a REF_ROWS, or not a correct REF_ROWS. [Comments] should already be filtered down per work order.
I recommend sticking to default appsheet behavior in most cases. Here, that means sticking with the default auto-generated [Related Work Order Comments] VC. Did you just rename that to “Comments” or have you done something else to it? One thing you can do is to “reset” the situation by:
Delete [Comments] and/or [Related…Comments]
In comments table, change the work-order Ref column to text
Save the editor
Change work-order column back to Ref
Save the editor again
This should regenerate the correct [Related…] column.
That worked. Looks like I renamed the original [Related Comments…] to something different while also creating another VC named “Comments.” Not sure what the heck I was thinking . Thanks, Marc!!