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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Super User
Super User

@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.


@ 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!:
The Definitive Guide to Power Query (M)

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
Super User
Super User

@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.


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Yup that fixed it. Thank you!!!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors