LOOKUP with a MAXROW

Iโ€™ve got a table: SCOPE and a table: NOTE (These are not reference together, and I do not want a helper virtual column. My data sets are very large.)
I have an action on the SCOPE table to LINKTOFORM to create a note. On Save I am attempting to pass that note to a column on the SCOPE table โ€œscope_current_mgt_noteโ€ I am using an action to โ€œExecute an action on a set of rowsโ€ And then I have my data change action, When I simply put in the MAXROW expression, it injects the correct row ref number. However, when I wrap it in a LOOKUP() it pushes a null value.

ANY(SELECT(
NOTE[note_text], MAXROW(โ€œNOTEโ€, โ€œnote_datetimeโ€, [note_REF_table]=[_THISROW])=[note_key]
))

Solved Solved
0 14 2,015
1 ACCEPTED SOLUTION

Could you try this:

INDEX(
ORDERBY(
FILTER(
โ€œNOTEโ€,
([note_REF_table] = [_THISROW])
),
[note_datetime],
TRUE
),
1
)

View solution in original post

14 REPLIES 14

Steve
Platinum 4
Platinum 4

Is the NOTE row being added as part of the SCOPE row addition?

No, the SCOPE record already exists. and I have a prominent action to create a note, using LINKTOFORM, where I capture the SCOPE keyโ€ฆ

I wish we could do something like MAXROW(โ€ฆ)[note_text]

I know right, And I canโ€™t figure out why wrapping maxrow in a lookup isnโ€™t workingโ€ฆ

Did you try :
INDEX(SELECT(NOTE[note_text], [note_key]=[_THISROW])), 1)

Basically from the SCOPE table column โ€œscope_current_mgt_noteโ€ Iโ€™m trying to return the most recent child note_text

The NOTE table has a column that caries the SCOPE keyโ€ฆ

Ok, maybe Iโ€™m not understanding your table structure. I guess you have multiple notes referring to the same scope and you want to fetch the latest note for that scope.
Can you verify if this is your setup?

SCOPE hasColumn:โ€œscope_current_mgt_noteโ€
SCOPE hasColumn:โ€œscope_keyโ€ isKey:TRUE
SCOPE hasAction:UpdateNote type:โ€Set the value of a Columnโ€ column1Name:โ€ scope_current_mgt_noteโ€ column1Value:
ANY(SELECT(
NOTE[note_text], MAXROW(โ€œNOTEโ€, โ€œnote_datetimeโ€, [note_REF_table]=[_THISROW])=[note_key]
))

NOTE hasColumn:โ€œnote_keyโ€ isKey:TRUE
NOTE hasColumn:โ€œ note_REF_tableโ€
NOTE hasColumn:โ€œnote_textโ€ isLabel:TRUE
NOTE hasAction:setNoteinScope type: โ€œExecute an action on a set of rowsโ€ targetTable:SCOPE fortheserows:โ€note_REF_tableโ€ actionToExecute:โ€UpdateNoteโ€œ

Yes sir, nailed it.

Could you try this:

INDEX(
ORDERBY(
FILTER(
โ€œNOTEโ€,
([note_REF_table] = [_THISROW])
),
[note_datetime],
TRUE
),
1
)

I wrapped that in a lookup, and it worked great!
thanks Jay!

You are welcome
It would still help to know why your original formula didnโ€™t work.

This how I suspect the expression expands:

ANY(
  SELECT(
    NOTE[note_text],
    (
      ANY(
        SELECT(
          NOTE[note_key],
          AND(
            ([note_REF_table] = [_THISROW]),
            (
              [note_datetime]
              = MAX(
                SELECT(
                  NOTE[note_datetime],
                  ([note_REF_table] = [_THISROW])
                )
              )
            )
          )
        )
      )
      = [note_key]
    )
  )
)

I see potential breakdowns if [note_REF_table] or [note_datetime] ever evaluate to blank, which would result in unexpected matches and thereby unexpected results.

Hereโ€™s how I suspect Jayโ€™s expression expands:

ANY(
  SELECT(
    NOTE[note_text],
    (
      [note_key]
      = INDEX(
        ORDERBY(
          SELECT(
            NOTE[note_key]],
            ([note_REF_table] = [_THISROW])
          ),
          [note_datetime],
            TRUE
        ),
        1
      )
    )
  )
)

Jayโ€™s is much more efficient, if nothing else.

Wow!! Thanks for that Steve๐Ÿ™

Not sure why it didn't let me respond to Grant but how did this get rapped into a LOOKUP? 

Top Labels in this Space