Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
arielcedola
Helper III
Helper III

Filter context issue trying to visualize top ranked items in different categories

Hi,

I'm working with a dataset containing the subcategories Area, Product and Article for different Shops, and the amount of sales by Article. For each shop the ranking of Area is determined according to the total sales. Then for the Area ranked 1 the ranking of Products is found, and for the Product ranked 1 the ranking of the Articles is in turn determined.

So, for each Shop, I have the top Article within the top Product subcategory within the top Area of that Shop. Three shops, three top articles.

table shops3.png

Now I need to compare the sales of each of these three top articles in all the shops in a bar chart, switching the top Article by means of the Shop slicer already existent in the canvas: selecting Shop A the chart must show the sales of the top Article in Shop A in all three shops, and so on (shops in x-axis).

My problem is with the Shop filter. In the measure I need to get the sales in all shops but at the same time filtering by shop in order to set the article. I tested this measure but it doesn't work:

NSalesBarChart = 
VAR
Rank1Article = CALCULATE(
SELECTEDVALUE(Sales[Article]), 
FILTER(VALUES(Sales[Article]), [Rank Article] = 1) 
)
RETURN

CALCULATE(MIN(Sales[ArticleNSales]), Sales[Article] = Rank1Article)

Ideas? Find below the link to the pbix file. Thanks!

https://drive.google.com/file/d/1eLWKETSCFSU0inPrFfVpyi2dI-DZ7tzj/view?usp=sharing

1 ACCEPTED SOLUTION
arielcedola
Helper III
Helper III

Solved. I modified the measure as follows:

NSalesBarChart = 
VAR
CurrentShop = CALCULATE(SELECTEDVALUE(TabellaShop[Shop]))
VAR
Rank1Article = CALCULATE(
        SELECTEDVALUE(Sales[Article]),    
        FILTER(VALUES(Sales[Article]), [Rank Article] = 1) 
)
RETURN

CALCULATE(MIN(Sales[ArticleNSales]), FILTER(ALL(Sales), Sales[Article] = Rank1Article && Sales[Shop] = currentShop))

I created an auxiliary table with the names of the shops (TabellaShop) and used these values on the x-axis of the bar chart. I filter the shop using this as a way to ignore the Shop filter context, applied rather to the selection of the top ranked Article to visualize.

Best,

Ariel

View solution in original post

4 REPLIES 4
arielcedola
Helper III
Helper III

Solved. I modified the measure as follows:

NSalesBarChart = 
VAR
CurrentShop = CALCULATE(SELECTEDVALUE(TabellaShop[Shop]))
VAR
Rank1Article = CALCULATE(
        SELECTEDVALUE(Sales[Article]),    
        FILTER(VALUES(Sales[Article]), [Rank Article] = 1) 
)
RETURN

CALCULATE(MIN(Sales[ArticleNSales]), FILTER(ALL(Sales), Sales[Article] = Rank1Article && Sales[Shop] = currentShop))

I created an auxiliary table with the names of the shops (TabellaShop) and used these values on the x-axis of the bar chart. I filter the shop using this as a way to ignore the Shop filter context, applied rather to the selection of the top ranked Article to visualize.

Best,

Ariel

amitchandak
Super User
Super User

For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale
https://community.powerbi.com/t5/Community-Blog/Dynamic-TopN-made-easy-with-What-If-Parameter/ba-p/3...

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

It's ugly, but some might find its simplicity beautiful. Just duplicate your sales table and display a separate chart from the second table yet filtered on your number one article.

 

It's probably easy to understand for an outsider when they need to work with your file vs. trying to understand the DAX code required for the fancy solution. Unless of course performance prohibits this solution.

 

Does this work for you? If so, please mark as solution.

 

Kind regards,

 

Steve. 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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

Top Solution Authors