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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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