Help with RANDBETWEEN expression

I have an onboarding view that displays one quote from a table of quotes. Since you can’t get rid of the Back button on Onboarding Views, I want it to display two quotes instead of one. At least the back button makes sense then.

Here is the row filter expression for the slice the view is based on.
AND([SORT_ORDER]=RANDBETWEEN(1,MAX(Encouragement[Sort_order])),[IN_APP]=TRUE)

How can I change it to pick two?

Thanks.

Solved Solved
0 2 134
1 ACCEPTED SOLUTION

Steve
Platinum 4
Platinum 4

The problem here is that the slice filter expression is evaluated anew for each row, so each evaluation will get a different result for from RANDBETWEEN(), and there’s no way for one row to know what another row got.

My suggestion is to add a virtual column to the Encouragement table named (e.g.) Random_order with an App formula expression of RANDBETWEEN(1, 999999). Then make your slice row filter expression:

IN(
  [_THISROW],
  TOP(
    ORDERBY(
      FILTER("Encouragement", TRUE),
      [Random_order],
        FALSE,
      [_ROWNUMBER]
        FALSE
    ),
    2
  )
)

View solution in original post

2 REPLIES 2

Steve
Platinum 4
Platinum 4

The problem here is that the slice filter expression is evaluated anew for each row, so each evaluation will get a different result for from RANDBETWEEN(), and there’s no way for one row to know what another row got.

My suggestion is to add a virtual column to the Encouragement table named (e.g.) Random_order with an App formula expression of RANDBETWEEN(1, 999999). Then make your slice row filter expression:

IN(
  [_THISROW],
  TOP(
    ORDERBY(
      FILTER("Encouragement", TRUE),
      [Random_order],
        FALSE,
      [_ROWNUMBER]
        FALSE
    ),
    2
  )
)

Thanks Steve. That is a huge help. My brain would not have been able to figure that out, at least not today.

Top Labels in this Space