cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

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
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.