Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
D_HL
Frequent Visitor

Random Sample

Hi everyone, 

 

Wondering if Power BI can select a random sample however with criteria. I have a data set and want a sample that has a good spread over 4 columns in the data. 

 

For example I want a good spread over Rating, Classification, Class and Business area in the data set below. 

 

e.g. data

Customer NameRatingClassificationClassBusiness AreaValue
A10GoodFailUK156000
B15WatchGoodUSA157
C12GoodSubUK850000
D14StressedGoodUK984500
E12StressedGoodUK178130
F12GoodFailUSA648491
G12WatchSubEU1658403
H10GoodSubUK97
I10StressedGoodUK1654846546
J10WatchFailUSA548
K15StressedGoodEU2126654
L19GoodFailUK21687
M19StressedGoodUK1576
N18GoodSubUSA5654698
O12StressedGoodUK3216768
P15WatchGoodUK351648
Q19GoodFailUK115849

 

Thanks 

 

1 ACCEPTED SOLUTION
D_HL
Frequent Visitor

Thanks for the response. I think I have solved with some Dax which creates a table for each column I want to randomise and forms a union of those tables. Its a long process but I think it will work. I just create a table per column for the sample spread? 

 

Random Selection with category filter and sample size =

VAR SampleSize = XX

VAR Cat_Name1TableWithRand =

TOPN (SampleSize, ADDCOLUMNS ( FILTER('Table_Name', 'Table_Name'[Column1] = "Cat_Name1"), "Rand", RAND () ), [Rand])

VAR Cat_Name2TableWithRand =

TOPN (SampleSize, ADDCOLUMNS ( FILTER('Table_Name', 'Table_Name'[Column1] = "Cat_Name2"), "Rand", RAND () ), [Rand])

VAR Cat_Name3TableWithRand =

TOPN (SampleSize, ADDCOLUMNS ( FILTER('Table_Name', 'Table_Name'[Column1] = "Cat_Name3"), "Rand", RAND () ), [Rand])

VAR UnionTable =

UNION (Cat_Name1TableWithRand , Cat_Name2TableWithRand , Cat_Name3TableWithRand )

 

RETURN UnionTable

 

If there is a quicker way, then great! 

 

View solution in original post

3 REPLIES 3
D_HL
Frequent Visitor

Thanks for the response. I think I have solved with some Dax which creates a table for each column I want to randomise and forms a union of those tables. Its a long process but I think it will work. I just create a table per column for the sample spread? 

 

Random Selection with category filter and sample size =

VAR SampleSize = XX

VAR Cat_Name1TableWithRand =

TOPN (SampleSize, ADDCOLUMNS ( FILTER('Table_Name', 'Table_Name'[Column1] = "Cat_Name1"), "Rand", RAND () ), [Rand])

VAR Cat_Name2TableWithRand =

TOPN (SampleSize, ADDCOLUMNS ( FILTER('Table_Name', 'Table_Name'[Column1] = "Cat_Name2"), "Rand", RAND () ), [Rand])

VAR Cat_Name3TableWithRand =

TOPN (SampleSize, ADDCOLUMNS ( FILTER('Table_Name', 'Table_Name'[Column1] = "Cat_Name3"), "Rand", RAND () ), [Rand])

VAR UnionTable =

UNION (Cat_Name1TableWithRand , Cat_Name2TableWithRand , Cat_Name3TableWithRand )

 

RETURN UnionTable

 

If there is a quicker way, then great! 

 

Hi, @D_HL 

 

Glad you found a solution.🤗

Okay, If your problem has been solved, you can mark your answer as solution to close the thread. 

 

Best Regards,
Community Support Team _ Janey

v-janeyg-msft
Community Support
Community Support

Hi, @D_HL 

 

vjaneygmsft_0-1648795553413.png

Do you want to randomly generate rate from the data in the next four columns?

There is no such method in powerbi, you need to define a complete rule yourself according to the classification.

 

Best Regards,
Community Support Team _ Janey

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.