cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Regular Visitor

Dynamic Order For TopN Function in DAX

I am new to DAX and probably making a noob mistake. I want to change my TopN order to asc or desc order based on whether the selected measure is summing to positive or negative. But so far, I have not been successful with the below code. I am not sure why the DAX is not accepting OrderTopN variable in order definition. I have been able to solve it the long way but I wanted to know why the below code ain't working?

 

VAR OrderTOPN =IF([ADPR.EM]>=0,1,0)

 

TopN.ADPR =
CALCULATE (
[ADPR.EM],
TOPN (
'mn-value'[n-value Value],
ALL ( 'mprofile'[Org_Name] ),
[ADPR.EM],OrderTOPN
),
VALUES ( 'mprofile'[Org_Name] )
)

 

RETURN TopN.ADPR

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

July 2020 Community Highlights

July 2020 Community Highlights

Learn about the exciting things that happened in July.

Upcoming Events

Upcoming Events

Wondering what events you could join or have an event to promote yourself? Check out our Upcoming Events.

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

We are thrilled to announce we will begin running a monthly webinar series named Power BI Dev Camp.

Top Solution Authors