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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

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
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

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.