Display a single, random row from a Slice

JTK
New Member

I have a Slice set up with expressions to filter out some records from a table.

I want to display a single, random row from that Slice within a View.

How would I go about doing this? Iโ€™ve seen the thread โ€œPick a random row from a tableโ€ but I donโ€™t know where to enter this expression. I added it as a formula in a virtual column in my table, but that doesnโ€™t seem to be getting me anywhere. Any help is appreciated!

0 5 534
5 REPLIES 5

Maybe make another Slice, with a row filter condition of:
[key-column] = /random-row-selection-expression/

There should be only 1 record in the new Slice.
Make a new UX->View based on the new Slice.

@Marc_Dillon

Sorry, as I tested the expression and typed the response, I did not see you have already replied.

Thanks so much @Marc_Dillon and @Suvrutt_Gurjar!! This helped me work it out. I greatly appreciate your responses.

You have mentioned that you already have a slice set up to filter some records. It sound that you wish to now further include a condition of any random row among the filtered records. If so, you will need to combine your existing slice filter expression and the expression that selects a random value as mentioned in post by @TyAlevizos , that you have referred.

Your slice filter condition can be something like

[Key]=INDEX(SELECT(Table Name[Key], [Status] =โ€œOpenโ€), RANDBETWEEN (1, COUNT(SELECT(Table Name[Key], [Status]=โ€œOpenโ€))))

Here [Status]=โ€œOpenโ€ is equivalent to your existing filter condition. Please replace it with the actual filter condition you have.
Basically , the combined expression selects records from the table based on your required condition and then among those selected records , the RANDBETWEEN() combined with INDEX() selects a random record.

I would suggest [Key]=Any(filter(table, <condition>))[key]

The the difference for me was that using the formula below returned slice of type not recognisable by app (could not use details, formatting, etc)
[Key]=INDEX(SELECT(Table Name[Key], [Status] =โ€œOpenโ€), RANDBETWEEN (1, COUNT(SELECT(Table Name[Key], [Status]=โ€œOpenโ€))))

 

Top Labels in this Space