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

RANK / MAX sales on any given day

Hi community, 

Im overthinking this one most likely.

I need to rank sales agents by both date and their sales for the day. 

If the rank is 1, they get a bonus for that day.

 

As im testing with the MAX and MAXX funcitons I find that I need something to filter on, which is why I believe a built in rank would be useful.

 

Here's what I got so far:

 

RANK test1 =
VAR _max = MAXX ( Sales , Sales[Sales] )
VAR _rank = RANKX ( Sales , FILTER(  _max on any given day  ) , )      ..... stuck on how to create the date / _max filter
VAR _bonus = SUMX ( Bonus, Bonus[Bonus] ) 
RETURN
IF (_rank = 1, _bonus , BLANK)
 

 

2022-09-30_11-46-39.png

1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

Hi , @kpickle 

Here are the steps you can refer to :

(1)This is my test data:

vyueyunzhmsft_0-1664851726870.png

(2)We can click "New Column" to create a column:

test = 
VAR _RANK=RANKX( FILTER( ALL('Sheet5') , 'Sheet5'[Date] =EARLIER(Sheet5[Date])) ,CALCULATE( SUM(Sheet5[Sales]),ALLEXCEPT('Sheet5','Sheet5'[Sales])),,DESC,Dense)
return 
IF(_RANK =1 ,'Sheet5'[Bonus] , BLANK())

(3)Then we can meet your need:

vyueyunzhmsft_1-1664851767988.pngvyueyunzhmsft_2-1664851777642.png

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

 

Best Regards,

Aniya Zhang

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

3 REPLIES 3
v-yueyunzh-msft
Community Support
Community Support

Hi , @kpickle 

Here are the steps you can refer to :

(1)This is my test data:

vyueyunzhmsft_0-1664851726870.png

(2)We can click "New Column" to create a column:

test = 
VAR _RANK=RANKX( FILTER( ALL('Sheet5') , 'Sheet5'[Date] =EARLIER(Sheet5[Date])) ,CALCULATE( SUM(Sheet5[Sales]),ALLEXCEPT('Sheet5','Sheet5'[Sales])),,DESC,Dense)
return 
IF(_RANK =1 ,'Sheet5'[Bonus] , BLANK())

(3)Then we can meet your need:

vyueyunzhmsft_1-1664851767988.pngvyueyunzhmsft_2-1664851777642.png

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

 

Best Regards,

Aniya Zhang

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

 

 

 

kpickle
Frequent Visitor

Update - I was playing around within the table tyring to go the calcualted column route using the following, but Im getting circular dependency errors Im trying to work through.

 

MAX_CalcColumn_test1 =
VAR _maxvalue =
CALCULATE (
    MAX( Sales[Sales] ),
    ALLEXCEPT( Sales, Sales[Date] ) )
 
RETURN
IF( Sales = _maxvalue, "MAX" )

 

Using "MAX" as result just to see if it works first.

Still a work in progress.

@kpickle ,

Here is a blog that provides a detailed explanation.

https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns

I believe you will find a scenario similar to yours (substitute his SubCategory with your Date )

Hope this helps.

Regards,

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.