Pick a random row from a table

To pick a random row of data from a table, the ANY() function will not suffice. Hereโ€™s a simple pattern to do this:

index(Test Score[Key],
randbetween(1, count(Test Score[Key]))
)

Where โ€œTest Scoreโ€ is your table name and โ€œKeyโ€ is that tableโ€™s key.

This sample app shows this in two ways:

  1. We format a row randomly. When you resync the app, a new random row will be selected each time (in bold red)

  2. We have an icon on the left side of the table which will assign a โ€œpersonโ€ to the โ€œtest scoreโ€ randomly.

This comes up from time to time in various situations and I didnโ€™t see an existing forum post. As usual, chime in if you have a better version!

6 4 1,153
4 REPLIES 4

NICE! This is like one of those perfectly reduced forms of an expression. Itโ€™s the cleanest, shortest way you could randomly select a record from a list of unknown length.

โ€ฆfor now

Maybe this should be a feature request!

RANDOM({list}) where the list could be a SELECT, FILTER, or any other list. And the value returned has the corresponding data-type of the source column (list of Refs, dates, etc).

Steve
Platinum 4
Platinum 4

Or:

ANY(
  ORDERBY(
    Test Score[Key],
    RANDBETWEEN(1, 999999)
  )
)

How do i get the return label column vs displaying the key column?

Top Labels in this Space