Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

TopN based on Measure instead of Column

Hi everyone, I am struggling with the TopN function and I hope you can help me out. Data: event registration data, with calculated columns for CY (current year) and LY (Last year). I also created a ...
  • Anonymous's avatar
    Anonymous
    6 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