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!
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.
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”))))
User | Count |
---|---|
16 | |
12 | |
5 | |
5 | |
5 |