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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Rankx problems ( Rankx within group, rankx and dateadd, rankx with slicer)

Hello everyone,

 

I found Rankx can be completed if used as a measure. Any help will be greatly appreciated! 

 

I have built a Date table and one to many relationship with the Test Table on the “Date” Column ( Please see the screenshot below).

WhistleBee_0-1646217311301.png

 

I would like to achieve the following:

Date

Link Code

 Volumes

PM Volumes

Rank

PM Rank

01/04/2021

A

18

 

3

1

01/04/2021

B

62

 

1

1

01/04/2021

C

19

 

2

1

01/05/2021

A

12

19

3

2

01/05/2021

B

103

12

1

3

01/05/2021

C

15

103

2

1

01/06/2021

A

33

15

1

3

01/06/2021

B

18

33

3

1

01/06/2021

C

29

18

2

2

However, this is what returned with my Dax below

Date

Link Code

 Volumes

PM Volumes

Rank

PM Rank

01/04/2021

A

18

 

3

1

01/04/2021

B

62

 

1

1

01/04/2021

C

19

 

2

1

01/05/2021

A

12

19

3

1

01/05/2021

B

103

12

1

1

01/05/2021

C

15

103

2

1

01/06/2021

A

33

15

1

1

01/06/2021

B

18

33

3

1

01/06/2021

C

29

18

2

1

 

Rank =

RANKX(filter(all('Test table'[Date],'Test table'[Link Code]),'Test table'[Date]=max('Test table'[Date])),CALCULATE(sum('Test table'[ Volumes])),,DESC)

 

PM Volumnes = CALCULATE(sum('Test table'[ Volumes]),dateadd('Dim Date 2'[Date],-1,month))

 

PM rank =

rankx(filter(all('Test table'[Date],'Test table'[Link Code]),'Test table'[Date]=max('Test table'[Date])),[PM Volumnes],,desc)

 

May I ask where I did wrong? Why PM Rank doesn’t return as expected?

 

Thank you.

 

Jing

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

Please try this code:

pm rank =
RANKX (
    CALCULATETABLE (
        ALLSELECTED ( 'Table'[Link Code] ),
        ALLEXCEPT ( 'Dim Date', 'Dim Date'[Date].[Day] )
    ),
    [PM Volumes],
    ,
    DESC
)

Result:

vchenwuzmsft_0-1646634325576.png

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

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

6 REPLIES 6
amitchandak
Super User
Super User

@Anonymous with time intelligence functions you need to use date table in visual too

 

try with these changes and date table in visual too

rankx(filter(all('Test table'[Date],'Test table'[Link Code]),'Test table'[Date]=max('Test table'[Date])),[PM Volumnes],,desc)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi Amichandak

 

Thank you for your help.

 

I am using the Date column from the Date table ('Dim Date 2'[Date]) in visual. PM Rank just doesn't return as expected.

 

The rankx Dax you provided is the same with mine?

 

Thank you.

 

Jing

 

 

@Anonymous , Please use in the rank too

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak 

 

Hi Amitchandak

 

Thank you for your reply.

 

I thought about using the Date column from the Dim Date table ('Dim Date 2'[Date])before. Below is the Dax I tried.

rankx(filter(all('Dim Date 2'[Date],'Test table'[Link Code]),'Dim Date 2'[Date]=max('Dim Date 2'[Date])),[PM Volumnes],,desc)

However, becaues the All function can only be used if the columns are from the same table,  the fomular above returned error. 

 

I also tried rankx(filter(all('Dim Date 2'[Date],'Test table'[Link Code]),'Test table'[Date]=max('Test table'[Date])),,desc), but it still didn't work either.

 

Thank you.

 

Jing

Hi @Anonymous ,

 

Please try this code:

pm rank =
RANKX (
    CALCULATETABLE (
        ALLSELECTED ( 'Table'[Link Code] ),
        ALLEXCEPT ( 'Dim Date', 'Dim Date'[Date].[Day] )
    ),
    [PM Volumes],
    ,
    DESC
)

Result:

vchenwuzmsft_0-1646634325576.png

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

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

Anonymous
Not applicable

@v-chenwuz-msft 

Hello

Thank you so much for your help! It works well.

However, I don't really understand the code. Would you mind explaining the following code?

CALCULATETABLE (
ALLSELECTED ( 'Table'[Link Code] ),
ALLEXCEPT ( 'Dim Date', 'Dim Date'[Date].[Day] )
 
Thank you.
 
Jing

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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