How to simplify a LIST / INDEX app formula?

I'm after ideas / methods / hints to simplify the following App Formula.
The result I want is a list of nearest 5 row references from the WAITING_LIST table where the CONTAINS criteria are met for each row_ref.
TIA
Screenshot 2024-08-21 at 11.10.10.png
The formula below works - but seems like it's the long way round.
Can I simplify the app formula that creates the list of row_refs?

 

LIST(
INDEX(
  ORDERBY(
    FILTER(
      "WAITING_LIST",
      CONTAINS([Related SECTIONs][_sectionType],[_suggestedSection])
    ),
    DISTANCE(
      [_memberPostcode_LatLong], 
      [groupLatLong]
    )
  ),1),
INDEX(
  ORDERBY(
    FILTER(
      "WAITING_LIST",
      CONTAINS([Related SECTIONs][_sectionType],[_suggestedSection])
    ),
    DISTANCE(
      [_memberPostcode_LatLong], 
      [groupLatLong]
    )
  ),2),
INDEX(
  ORDERBY(
    FILTER(
      "WAITING_LIST",
      CONTAINS([Related SECTIONs][_sectionType],[_suggestedSection])
    ),
    DISTANCE(
      [_memberPostcode_LatLong], 
      [groupLatLong]
    )
  ),3),
INDEX(
  ORDERBY(
    FILTER(
      "WAITING_LIST",
      CONTAINS([Related SECTIONs][_sectionType],[_suggestedSection])
    ),
    DISTANCE(
      [_memberPostcode_LatLong], 
      [groupLatLong]
    )
  ),4),
INDEX(
  ORDERBY(
    FILTER(
      "WAITING_LIST",
      CONTAINS([Related SECTIONs][_sectionType],[_suggestedSection])
    ),
    DISTANCE(
      [_memberPostcode_LatLong], 
      [groupLatLong]
    )
  ),5)
)

 

 

Solved Solved
0 3 183
1 ACCEPTED SOLUTION

It sounds that you are looking for TOP() function?

In that case, please try the below expression: 

TOP( ORDERBY(
FILTER(
"WAITING_LIST",
CONTAINS([Related SECTIONs][_sectionType],[_suggestedSection])
),
DISTANCE(
[_memberPostcode_LatLong],
[groupLatLong]
)
) , 5)

 

TOP() - AppSheet Help

 

View solution in original post

3 REPLIES 3

It sounds that you are looking for TOP() function?

In that case, please try the below expression: 

TOP( ORDERBY(
FILTER(
"WAITING_LIST",
CONTAINS([Related SECTIONs][_sectionType],[_suggestedSection])
),
DISTANCE(
[_memberPostcode_LatLong],
[groupLatLong]
)
) , 5)

 

TOP() - AppSheet Help

 

Genius - not come across that function before.  Thank you, replaced my app formula perfectly.

You are welcome.