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
sekinod
Helper II
Helper II

Getting the product sales by month for TOP N customers

1.JPGI am able to get the TOP N customer sales as an above table  with following command

new top = 
VAR RankingDimension = VALUES(Customers[Customer Name])
return
CALCULATE([Total Sales],
FILTER(RankingDimension,RANKX(ALL(Customers[Customer Name]),[Total Sales],,DESC)<=[selected N]))

but when I use it with month or product name I get the following table

2.JPG

 

Total is shown is here correct but values are not matching. Please help me with this

Thank you in advance

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

@sekinod when you put month or product in the rows, then the second parameter of RANKX, [total sales], will bring in these filter context into the calculation. so in each row it  calculates topn in that month or product. 

new top = 
VAR RankingDimension = VALUES(Customers[Customer Name])
return
CALCULATE([Total Sales],
FILTER(RankingDimension,RANKX(ALL(Customers[Customer Name]),VAR c=Customers[Customer Name] RETURN CALCULATE([Total Sales],ALLSELECT(),Customers[Customer Name]=c),,DESC)<=[selected N]))

 

View solution in original post

4 REPLIES 4
wdx223_Daniel
Super User
Super User

@sekinod when you put month or product in the rows, then the second parameter of RANKX, [total sales], will bring in these filter context into the calculation. so in each row it  calculates topn in that month or product. 

new top = 
VAR RankingDimension = VALUES(Customers[Customer Name])
return
CALCULATE([Total Sales],
FILTER(RankingDimension,RANKX(ALL(Customers[Customer Name]),VAR c=Customers[Customer Name] RETURN CALCULATE([Total Sales],ALLSELECT(),Customers[Customer Name]=c),,DESC)<=[selected N]))

 

Much appreiciated for your help. 

If it is not trouble could you please explain your code.

@sekinod depending on the data what you show, i think you want RANKX only considers the Customer Name, ingoring whatever other filter context. so,  i used a allselect() to remove all the filters in the visual, then used Customers[Customer Name]=c to reapply the filter on Customer Name.

mahoneypat
Employee
Employee

Not sure but try using VALUES in your RANKX instead of ALL (or re-use your rankingdimension variable there).

 

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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.

Top Solution Authors