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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Jessie_Ip
Regular Visitor

RANKX shows all 1 even if I use ALL at table and CALCULATE

Hi there,

 

I have issue for RANKX.

 

All fields are from same table with below column:

DOD - a date with year, quarter, month, day

 

I want to rank the count of DOD by monthly basis and sort from Jan to Dec. The Month column is from DOD.

Here's the DAX: 

DoD Rank =
RANKX(ALL(BEREAVEMENTRAW), CALCULATE(COUNT(BEREAVEMENTRAW[DOD].[Date])),,desc,Dense)

 

Jessie_Ip_0-1707235115649.png

I've already used ALL at table and CALCULATE to do the context transition. any advise why it still show 1 for all?

 

Many thanks,

Jessie

 

 

1 ACCEPTED SOLUTION

Hi, @Jessie_Ip 

Thank you for your reply. I understand your concerns, so I came up with a new way to calculate rankings. I created a new summary table through SUMMARIZE, and calculated the correct ranking through this summary table. According to your description DOD is date type data, I created the following data:

vjianpengmsft_0-1708416913144.png

Create a new calculation table using the following DAX expression:

Table=SUMMARIZE (
    'Sheet5',
    Sheet5[Date].[Month],
    "Count DOD", CALCULATE ( COUNT ( 'Sheet5'[DOD] ), MONTH ( 'Sheet5'[DOD] ) )
)

The summary results are as follows:

vjianpengmsft_1-1708417071651.png

Create a new column in this table for ranking. The DAX expression is as follows:

Rank = RANKX('Table','Table'[Count DOD],,DESC,Dense)

Ranking as follows:

vjianpengmsft_4-1708417573186.png

 

Put this column into table visual:

vjianpengmsft_5-1708417594735.png

I've provided the PBIX file used this time below. If you have any questions please let me know and I'll be happy to answer them.

 

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

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

7 REPLIES 7
vivek31
Frequent Visitor

DoD Rank =
RANKX(ALL(BEREAVEMENTRAW[month])CALCULATE(COUNT(BEREAVEMENTRAW[DOD].[Date])),,desc,Dense)
Jessie_Ip
Regular Visitor

Hi @bhanu_gautam ,

 

I have tried as below:

DoD Rank =
RANKX(
    ALL(BEREAVEMENTRAW[DOD]),
    CALCULATE(
        COUNTROWS(BEREAVEMENTRAW),
        BEREAVEMENTRAW[DOD].[Month]), ,desc,Dense)
 
but it shows:
 
9.PNG

 i check DOD and it's datetime format as '25/02/2020 00:00:00' not value January. Any advise?

 

Thanks,

Jessie

v-jianpeng-msft
Community Support
Community Support

Hi, @Jessie_Ip 

 

I'm happy to answer your questions. We can achieve ranking by calculating columns and measures:

1.Implemented through measure

We need to create two measures, measure2 is used to aggregate Count of DOD, measure is used to rank

Measure2 DAX formula:

Measure 2 = SUM(Sheet3[Count of DOD])

Measure DAX formula:

Measure = CALCULATE(RANKX(ALL('Sheet3'),[Measure 2],,DESC,Dense))

The results are as follows:

7.png

2.Ranking is achieved by calculate columns:

Calculate columns DAX formula

Column = RANKX(ALL(Sheet3),Sheet3[Count of DOD],,DESC,Dense)

The results are as follows:

7.png

I have provided the sample PBIX file used this time below. If the above suggestions are helpful to you, that would be great.

 

 

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

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

Hi @v-jianpeng-msft 

 

Thank you for reply. DOD is a date so i use count as below:

COUNT_DOD = CALCULATE(COUNT(BEREAVEMENTRAW[DOD]), MONTH(BEREAVEMENTRAW[DOD]))
 
Then follow your way:
RANKX_DOD = CALCULATE(RANKX(ALL(BEREAVEMENTRAW), [COUNT_DOD],, DESC, Dense))
 
And it still show 
Jessie_Ip_0-1708013454487.png

 

DOD is like this format: 25/02/2020 00:00:00

 

Any advise?

 

From what i find, I can't share the pbix file. If you can advise other way to share the file, I can try!

 

Many thanks,

Jessie

Hi, @Jessie_Ip 

Thank you for your reply. I understand your concerns, so I came up with a new way to calculate rankings. I created a new summary table through SUMMARIZE, and calculated the correct ranking through this summary table. According to your description DOD is date type data, I created the following data:

vjianpengmsft_0-1708416913144.png

Create a new calculation table using the following DAX expression:

Table=SUMMARIZE (
    'Sheet5',
    Sheet5[Date].[Month],
    "Count DOD", CALCULATE ( COUNT ( 'Sheet5'[DOD] ), MONTH ( 'Sheet5'[DOD] ) )
)

The summary results are as follows:

vjianpengmsft_1-1708417071651.png

Create a new column in this table for ranking. The DAX expression is as follows:

Rank = RANKX('Table','Table'[Count DOD],,DESC,Dense)

Ranking as follows:

vjianpengmsft_4-1708417573186.png

 

Put this column into table visual:

vjianpengmsft_5-1708417594735.png

I've provided the PBIX file used this time below. If you have any questions please let me know and I'll be happy to answer them.

 

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

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

 

 

Nathan321
Regular Visitor

The All(Berevementraw) needs a column reference, such as ALL(BEREVEMENT[DOD])

bhanu_gautam
Super User
Super User

@Jessie_Ip , Try using below method 

 

DoD Rank =
RANKX(
ALL(BEREAVEMENTRAW[DOD]),
CALCULATE(
COUNTROWS(BEREAVEMENTRAW),
BEREAVEMENTRAW[DOD].[Month]
),
,
DESC,
Dense
)

 

Please accept as solution and give kudos if it helps




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

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.