Can't get RandomSample to work

I need to click this button to change a value of 5 randomly selected rows. The formula in the screenshot can be entered without error, but when I click the button, either nothing happens or I get a “reading” error message. What am I doing wrong?

Hi @Ross_Chehayeb1 :blush: !

I think there’s just a condition missing in the Custom Filter of your button :blush:
(As in the Custom Filter you used Table.RandomSample(5) which is then compared to nothing)

The Custom Filter could be something like (See button “Random 1” in the sample below) :

CurrentValue.Contains(Table.RandomSample(5))

CurrentValue represents here each row from your table which will then be compared to whatever rows RandomSample() is currently returning …

In other words, this will tell to the Custom Filter to keep only the rows containing the 5 random rows RandomSample() is returning and then modify the checkbox for those rows :blush:

You could have also used a complete Action Formula instead :blush: such as this one :
(See button “Random 2”)

Table.RandomSample(5).ModifyRows(
  Table.[Column 2],True()
)

… Which I just find easier as there’s no need for the filter :blush:
(Table.RandomSample(5) already returns a list of 5 rows which ModifyRows() can use and do what it needs to do :blush: )

Hope this helps :blush: !

2 Likes

The second option worked! Thank you so much.

2 Likes

No problem @Ross_Chehayeb1 :relaxed: !

Glad to know it helped :grin: !

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.