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
annag815
Frequent Visitor

Random Sample of Data

Hi, this is my first time posting here so apologies if I am doing something wrong.

 

I am trying to return a table with a random sample of data. So far I have a new table: 

TableWithRand =

VAR SampleSize = 10
VAR SampleSize5= .05 * COUNTROWS(Sheet1)
VAR TableWithRand =
ADDCOLUMNS ( Table1, "Rand", RAND () )
RETURN
TOPN(SampleSize5, TableWithRand, [Rand])
 
And that works. However I want to modify it and add a condition like this: 
RETURN
If (SampleSize5 > 10,TOPN(SampleSize5, TableWithRand, [Rand]), TOPN(SampleSize, TableWithRand, [Rand]) )
 
and I get a "The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value." 
 
Feels like I am missing somethign really simple. Any ideas? Thanks in advance!
 
1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@annag815 - Equations that use SWITCH and IF to return different tables tend to fail. Create a variable, MySampleSize that chooses between SampleSize5 and SampleSize. Then use this in a single TOPN function.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
ysf
Helper I
Helper I

Hi there @Greg_Deckler 

 

I have this dax code which works well but now i want to make it dynamic

 

Sample Table = Sample(VALUE("45"),FILTER('TableReload', 'TableReload'[Product House] = "ASH") ,0)
 
Firstly the Product House changes
I want to have a user select on the dropdown of Product house and thereafter see sample which relates to selection 
if no selection is made then to return sample of whole table.
 
Please asssist me.
 
I have tried if statement and saw that they don't work
I have tried varibales and even combined with measure for the selected value but does filter sample to value.
--Sample(VALUE("45"),FILTER('TableReload', 'TableReload'[Product House] = [Selected Product]) ,0)
 
Greg_Deckler
Community Champion
Community Champion

@annag815 - Equations that use SWITCH and IF to return different tables tend to fail. Create a variable, MySampleSize that chooses between SampleSize5 and SampleSize. Then use this in a single TOPN function.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Yup that fixed it. Thank you!!!

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.