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
Ritvik777
Frequent Visitor

Unable to use TOPN slicer with a legend in a clustered column chart

Hi All,

 

So I am creating a clustered bar chart which shows the Sales by TOP N companies. Users can select N (5,10,15 etc) depending on the number of companies they want to see. 

 

For that i am using the DAX expression: 

TopNSales =
VAR selectedV = SELECTEDVALUE(TopY[Value])

RETURN
SWITCH(TRUE(),

selectedv=0,[Sales],


RANKX(ALLSELECTED(Fact[Company]),
[Sales])
<=selectedV,
[Sales]


)
 
But the Problem arises here: As soon as I enter the field called "Category" in the legend of the clustered bar chart, it no longer works the way it should. 
 
Is there a workaround this? If yes please do help me out.
 
Regards.
1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @Ritvik777 

I think you can try TopN function in cluster bar visual directly.

1.png

Result is as below.

2.png

If you want to achieve your goal by measure, try this code.

TopNSales = 
VAR _SelectedV =
    SELECTEDVALUE ( 'Top N'[Value] )
VAR _RANK =
    RANKX ( ALLSELECTED ( 'Sample'[Company] ), [M_Sales] )
RETURN
    IF (
        ISFILTERED ( 'Top N'[Value] ),
        IF ( _RANK <= _SelectedV, [M_Sales], BLANK () ),
        [M_Sales]
    )

 

By default it will show all values.

1.png

Select 5 in slicer, result is as below.

2.png

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-rzhou-msft
Community Support
Community Support

Hi @Ritvik777 

I think you can try TopN function in cluster bar visual directly.

1.png

Result is as below.

2.png

If you want to achieve your goal by measure, try this code.

TopNSales = 
VAR _SelectedV =
    SELECTEDVALUE ( 'Top N'[Value] )
VAR _RANK =
    RANKX ( ALLSELECTED ( 'Sample'[Company] ), [M_Sales] )
RETURN
    IF (
        ISFILTERED ( 'Top N'[Value] ),
        IF ( _RANK <= _SelectedV, [M_Sales], BLANK () ),
        [M_Sales]
    )

 

By default it will show all values.

1.png

Select 5 in slicer, result is as below.

2.png

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.