Forum Discussion

TBD56's avatar
TBD56
New Member
1 year ago
Solved

Top N filter with computed N

I have "simple" challenge, but can't find a solution:

 

I have table of cases created over a time period.

This table is filtered for cases within  a certain time period. From this subset I need to take a random sample. However, the sample size is dependent on the size of the (filtered) table:

 

Less than 10 cases -take 2 cases

Less than 100 cases - take 20%, at most 10

More than 100 cases - take 10%, at most 100

 

  • The random sample part is easy (add column "rand", filled with RAND() and take top N filter)
  •  

But, how make that "N" dependent on the table size?

 

 

 

 

  • TBD56's avatar
    TBD56
    1 year ago

    we figured out a different approach that works

5 Replies

  • Deku's avatar
    Deku
    Icon for Super User rankSuper User

    You could use SAMPLE instead of RAND and TOPN.

     

    Var cnt = countrows( table)

    Var n = Switch(

    True,

    Cnt < 10, 2

    Cnt< 20, 10,

    Cnt <= 100,  cnt * 0.2,

    Cnt <= 1000, cnt * 0.1,

    100

    )

    Return 

    Sample( n, table )

  • v-hashadapu's avatar
    v-hashadapu
    Icon for Community Support rankCommunity Support

    Hi TBD56 , Thank you for reaching out to the Microsoft Community Forum.

    Please let us know if your issue is solved. If it is, consider marking the answers that helped 'Accept as Solution', so others with similar queries can find them easily. If not, please share the details.
    Thank you.

  • v-hashadapu's avatar
    v-hashadapu
    Icon for Community Support rankCommunity Support

    Hi TBD56 , Please let us know if your issue is solved. If it is, consider marking the answer that helped 'Accept as Solution', so others with similar queries can find it easily. If not, please share the details.
    Thank you.

    • TBD56's avatar
      TBD56
      New Member

      we figured out a different approach that works

      • v-hashadapu's avatar
        v-hashadapu
        Icon for Community Support rankCommunity Support

        Hi TBD56 , We are pleased to hear that you have found a workaround that works. Kindly let us know if it successfully resolved your issue on permanent basis. If it did, please share the details here and mark it as 'Accept as solution' to assist others with similar problems. If it did not, please provide further details.
        Thank you.