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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.