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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
KAATA
Helper I
Helper I

RANKX returning duplicate values

Hi Power BI Community,

The below measure is supposed to return ranking based on the Region and the Continent columns.

The purpose is to consider both scopes – but independently of each other.

However, the measure returns rank 2 for two of the Regions - see screenshot below.

If I use ROUND for the Total Sales Measure, it works fine.

But why do I need to use ROUND?

The values are already quite different (about 24,000 for Southeast and 16,000 for Canada).

Looking for some DAX experts to help me out understanding this.

Thanks in advance 🙂

Measure 1: 

Rank Sales (considering hierarchy) =
IF(
    ISINSCOPE (DimTerritory[Region]),
    RANKX(ALLEXCEPT(DimTerritory, DimTerritory[Continent]), [Total Sales]),
    IF(
        ISINSCOPE(DimTerritory[Continent]),
        RANKX(ALLSELECTED(DimTerritory[Continent]), [Total Sales])
        )
    )
KAATA_0-1698413677667.png

 




2 ACCEPTED SOLUTIONS
lbendlin
Super User
Super User

yeah, that doesn't look right. Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue.
If you are unsure how to do that please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.

If you want to get answers faster please refer to https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

View solution in original post

Thank you for the reply, @Ahmedx.

I solved the issue in the following way:

First, I changed the data type for the Unit price from decimal number to whole number (in Power Query Editor).
I use Unit price to calculate the Total Sales:

Total Sales =
SUMX(
    FactSales,
    FactSales[Order Quantity] * FactSales[Unit Price]
)
 
Next, I used the below formula to calculate the ranking:
Rank Sales (disregarding hierarchy) =
IF(
    ISINSCOPE(DimTerritory[Region]),
    RANKX(
        ALLSELECTED(DimTerritory),
        [Total Sales]
    ),
    IF(
       ISINSCOPE(DimTerritory[Continent]),
    RANKX(
        ALLSELECTED(DimTerritory[Continent]),
        [Total Sales]
    )
    )
)
 
As a result, I obtain the correct result:
KAATA_1-1698741793139.png

 

 

 

The only confusion left is why I had to change the data type from decimal to whole number for this to work.
But for now the issue is solved.

View solution in original post

4 REPLIES 4
Ahmedx
Super User
Super User

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Screenshot_2.png

Thank you for the reply, @Ahmedx.

I solved the issue in the following way:

First, I changed the data type for the Unit price from decimal number to whole number (in Power Query Editor).
I use Unit price to calculate the Total Sales:

Total Sales =
SUMX(
    FactSales,
    FactSales[Order Quantity] * FactSales[Unit Price]
)
 
Next, I used the below formula to calculate the ranking:
Rank Sales (disregarding hierarchy) =
IF(
    ISINSCOPE(DimTerritory[Region]),
    RANKX(
        ALLSELECTED(DimTerritory),
        [Total Sales]
    ),
    IF(
       ISINSCOPE(DimTerritory[Continent]),
    RANKX(
        ALLSELECTED(DimTerritory[Continent]),
        [Total Sales]
    )
    )
)
 
As a result, I obtain the correct result:
KAATA_1-1698741793139.png

 

 

 

The only confusion left is why I had to change the data type from decimal to whole number for this to work.
But for now the issue is solved.

lbendlin
Super User
Super User

yeah, that doesn't look right. Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue.
If you are unsure how to do that please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.

If you want to get answers faster please refer to https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Hi @lbendlin,
I solved the issue in the following way:

First, I changed the data type for the Unit price from decimal number to whole number (in Power Query Editor).
I use Unit price to calculate the Total Sales:

Total Sales =
SUMX(
    FactSales,
    FactSales[Order Quantity] * FactSales[Unit Price]
)
 
Next, I used the below formula to calculate the ranking:
Rank Sales (disregarding hierarchy) =
IF(
    ISINSCOPE(DimTerritory[Region]),
    RANKX(
        ALLSELECTED(DimTerritory),
        [Total Sales]
    ),
    IF(
       ISINSCOPE(DimTerritory[Continent]),
    RANKX(
        ALLSELECTED(DimTerritory[Continent]),
        [Total Sales]
    )
    )
)
 
As a result, I obtain the correct result:
KAATA_0-1698741562442.png

 

 

The only confusion left is why I had to change the data type from decimal to whole number for this to work.
But for now the issue is solved.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.