Forum Discussion

killer85's avatar
killer85
Regular Visitor
1 year ago
Solved

Generating Dynamic Random Sample in Power BI with Custom Constraints

Hello Power BI Community, I hope you’re all doing well! I’m currently working on a project where I need to generate a dynamic random sample from a dataset of approximately 4,000 to 5,000 rows, with...
  • lbendlin's avatar
    lbendlin
    1 year ago

    Here is a sample setup, assuming even distribution. 

     

    Table:

     

     

    Samples = ADDCOLUMNS(GENERATESERIES(1,5000),"Rand",RAND())

     

     

    Filter Measure:

     

     

    Include = if(sum(Samples[Rand])<=[Sample size Value],1,0)

     

     

    If you need it more precise, use percentilex.:

    Include = if(sum(Samples[Rand])<=PERCENTILEX.INC(all(Samples[Rand]),[Rand],[Sample size Value]),1,0)

    Row count measure:

     

     

    Included Rows = COUNTROWS(FILTER(Samples,[Include]=1))