Forum Discussion
TopN based on Measure instead of Column
- Anonymous6 years ago
This piece of code:
Largest Deficit Region = CALCULATE( SELECTEDVALUE('Sample Data'[Region]), TOPN(1, 'Sample Data', [CY - LY Reg Diff], ASC ) )returns BLANK because SELECTEDVALUE returns BLANK when there is more than 1 region returned.
Change the expression under CALCULATE to show the number of regions - distinctcount( 'sample data'[region] ) - and you'll see it's not 1.
Please read this: https://dax.guide/topn/
Best
D
Could you use ADDCOLUMNS to add your TOPN column and then take the MIN or MAX of it?
Hi, I must be doing something wrong here. I added ADDCOLUMNS to the expression, but now it looks like it's using it as multiple columns- I thought that I only added one. 😞
- Anonymous6 years agoNot applicable
This piece of code:
Largest Deficit Region = CALCULATE( SELECTEDVALUE('Sample Data'[Region]), TOPN(1, 'Sample Data', [CY - LY Reg Diff], ASC ) )returns BLANK because SELECTEDVALUE returns BLANK when there is more than 1 region returned.
Change the expression under CALCULATE to show the number of regions - distinctcount( 'sample data'[region] ) - and you'll see it's not 1.
Please read this: https://dax.guide/topn/
Best
D
- Anonymous6 years agoNot applicable
Thank you- I was actually able to get it to work!