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
Anonymous
Not applicable

Dynamic Axis and Top N - retain rank with legend

Hi,
 
I have the following DAX expression which works well, to a point:
 
Nielsen - Spend, Dynamic Top N = VAR SelectedTop = SELECTEDVALUE('Top N'[Top N])
RETURN
SWITCH(TRUE(),SelectedTop=0,[Nielsen - Spend, Dynamic],
RANKX(ALLSELECTED('Spend (Nielsen) Dynamic Axis'[Axis]),[Nielsen - Spend, Dynamic])<=SelectedTop,[Nielsen - Spend, Dynamic])
 
  • [Top N] is a WhatIf Parameter
  • Dynamic Axis comes from a table I've created that lists each categorisation and all the options that appear within each. In this instance the axis will change from Advertiser to Product and will give a list of each when selected.
  • [Nielsen - Spend, Dynamic] is a measure that returns a metric depending on the selection of the dynamic axis. In this instance it's the same value, the sum of spend
I'm using this to have a dynamic axis and Top N feature appear in one chart. Below is an image to illustrate this:
 
This shows top 10 Products:
Top 10 Products.PNG
This is the same chart showing top 5 Advertisers:
Top 5 Advertisers.PNG
 
This works exactly how I want it to. However, I have a field that identifies which Advertiser/Product is the Client and which is a Competitor. When I add this into the legend I get more bars that the TopN filter should show, as shown below:
Top 5 Advertisers by Competitor Flag.PNG
This should show the Top 5 Advertisers, all of which should be Competitors. But instead it's also bringing back one bar for the Client. The field I'm using in my legend is called CompetitorFlag.
 
I feel like this needs to go into the DAX expression above but I'm not sure where or how. 
 
Any suggestions?

Thanks,
MarkJames
1 ACCEPTED SOLUTION
Mi2n
Employee
Employee

Hi Mark,

 

First off, very well articulated question. Kudos for that!

 

I think the issue could be that the Rank is calculated separately for both the categories (Client and Competitors). To solve that, you can change your DAX expression into the following,

 

Nielsen - Spend, Dynamic Top N =
VAR SelectedTop =
    SELECTEDVALUE ( 'Top N'[Top N] )
RETURN
    SWITCH (
        TRUE (),
        SelectedTop = 0, [Nielsen - Spend, Dynamic],
        RANKX (
            CROSSJOIN(
                ALLSELECTED ( 'Spend (Nielsen) Dynamic Axis'[Axis] ),
                ALLSELECTED ( '<Table Name>'[CompetitorFlag])
                ),
            [Nielsen - Spend, Dynamic]
        ) <= SelectedTop,  [Nielsen - Spend, Dynamic]
    )

 

Let me know if this helps.

 

Regards,

Mi2n

 

View solution in original post

2 REPLIES 2
Mi2n
Employee
Employee

Hi Mark,

 

First off, very well articulated question. Kudos for that!

 

I think the issue could be that the Rank is calculated separately for both the categories (Client and Competitors). To solve that, you can change your DAX expression into the following,

 

Nielsen - Spend, Dynamic Top N =
VAR SelectedTop =
    SELECTEDVALUE ( 'Top N'[Top N] )
RETURN
    SWITCH (
        TRUE (),
        SelectedTop = 0, [Nielsen - Spend, Dynamic],
        RANKX (
            CROSSJOIN(
                ALLSELECTED ( 'Spend (Nielsen) Dynamic Axis'[Axis] ),
                ALLSELECTED ( '<Table Name>'[CompetitorFlag])
                ),
            [Nielsen - Spend, Dynamic]
        ) <= SelectedTop,  [Nielsen - Spend, Dynamic]
    )

 

Let me know if this helps.

 

Regards,

Mi2n

 

Anonymous
Not applicable

Thanks @Mi2n, that has worked beautifully.

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.