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
CarlsBerg999
Helper V
Helper V

Ranking by subcategory

Hi, 

 

I'm trying to create a rank -column as described below. The idea is to rank the largest customers by revenue for each year. So for example, Customer A has the largest sales in each year, so it is ranked as no 1 each year.  Below is the goal:

 

Customer IDrankYearCustomer NameRevenue
1005412021Customer A4 755 136,39 €
4003922021Customer B4 027 475,56 €
4001432021Customer C2 449 284,35 €
1005412022Customer A4 717 788,69 €
1008222022Customer D2 217 147,99 €
1005412023Customer A6 408 845,84 €

 

My DAX is currently as follows:

rank =

VAR RankCustomersBySales =

RANKX (
'Visuals Customer',
CALCULATE (
SUM('Visuals Customer'[Revenue]),
'Task'[Task Status] <> "Stopped",
'Sub-Task'[Status] <> "Cancelled",
ALLEXCEPT ('Visuals Customer','Visuals Customer'[Customer ID])
),
,
DESC
)

RETURN

RankCustomersBySales




However, this is not producing the expected outcome. How do i write this dax?

1 ACCEPTED SOLUTION
smpa01
Super User
Super User

@CarlsBerg999  you can achieve this with two measures

_rev =
SUM ( 'Table 1'[Revenue] )

_rank =
RANKX (
    FILTER ( ALLSELECTED ( 'Table 1' ), 'Table 1'[Year] = MAX ( 'Table 1'[Year] ) ),
    [_rev],
    ,
    DESC
)

 

smpa01_0-1640872309114.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

6 REPLIES 6
v-yalanwu-msft
Community Support
Community Support

Hi, @CarlsBerg999 ;

Here is dax by create a column or create a measure as follows:

rankmeasure = 
VAR RankCustomersBySales =
    RANKX (
       FILTER(ALL('Visuals Customer'),[Year]=MAX([Year])),
       CALCULATE( SUM([Revenue])),
       ,
        DESC,Dense
    )
RETURN
    RankCustomersBySales
RankCol = RANKX(FILTER(ALL('Visuals Customer'),[Year]=EARLIER([Year])),[Revenue],,DESC,Dense)

The final output is shown below:

vyalanwumsft_0-1641173753013.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

smpa01
Super User
Super User

@CarlsBerg999  you can achieve this with two measures

_rev =
SUM ( 'Table 1'[Revenue] )

_rank =
RANKX (
    FILTER ( ALLSELECTED ( 'Table 1' ), 'Table 1'[Year] = MAX ( 'Table 1'[Year] ) ),
    [_rev],
    ,
    DESC
)

 

smpa01_0-1640872309114.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Jihwan_Kim
Super User
Super User

Picture1.png

 

Rank CC =
VAR currentyear = Data[Year]
VAR year_table =
FILTER ( data, Data[Year] = currentyear )
RETURN
RANKX ( year_table, Data[Revenue],, DESC )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


amitchandak
Super User
Super User

@CarlsBerg999 , Try measure like

 

Revenue M = CALCULATE (
SUM('Visuals Customer'[Revenue]),
'Task'[Task Status] <> "Stopped",
'Sub-Task'[Status] <> "Cancelled",
)

rank =

VAR RankCustomersBySales =

RANKX ( filter( summarize(allselected('Visuals Customer'), 'Visuals Customer'[Customer Name], 'Visuals Customer'[Year]),
[Year] =max([year]))
,[Revenue M],,
DESC
)

RETURN

RankCustomersBySales

 

 

or

 

rank =

VAR RankCustomersBySales =

RANKX ( filter( summarize(allselected('Visuals Customer'), 'Visuals Customer'[Customer Name],

'Visuals Customer'[Customer ID]

,'Visuals Customer'[Year]),
[Year] =max([year]))
,[Revenue M],,
DESC
)

RETURN

RankCustomersBySales

Hi,

 

These solutions use ALLSELECTED which would refer more to a visual? These are not producing the wanted outcome, I need a calculated column for this. 

@CarlsBerg999 , for column use revenue column

 

RANKX ( filter( 'Visuals Customer', 'Visuals Customer'[Year] = earlier('Visuals Customer'[Year]))
,'Visuals Customer'[Revenue],,
DESC
)

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.