Forum Discussion
annag815
6 years agoFrequent 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!
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.
3 Replies
- Greg_DecklerCommunity 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.
- annag815Frequent Visitor
Yup that fixed it. Thank you!!!
- ysfHelper 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 changesI want to have a user select on the dropdown of Product house and thereafter see sample which relates to selectionif 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 workI 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)