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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

Ranking where table does not have unique values

Hi,

I'm working on a dataset where I want to rank based on a label. The table does not have unique values due to sales happening for the same label type in multiple countries at the same day. I've watched the RANKX video by SQLBI where it needs to be unique values based on the customer code, it's not possible here due to the same value not being unique. How would you tackle the issue? With a crossjoin? It doesn't return the correct value if i'm using the following DAX measure:

Rank by Label v1 =
VAR articleCount = Measurements[Article Count]
VAR calcs =
IF(
HASONEVALUE(planned_and_purchased[Label ID]),
VAR maxLabelID =
CALCULATE( MAX(planned_and_purchased[Label ID]), REMOVEFILTERS() )
VAR lookUpTable =
ADDCOLUMNS(
ALLSELECTED(planned_and_purchased),
"@Art Qty", articleCount * maxLabelID + (planned_and_purchased[Label ID])
)
VAR currentValue =
articleCount * maxLabelID + SELECTEDVALUE( planned_and_purchased[Label ID])
VAR result = RANKX( lookUpTable, [@Art Qty], currentValue)

RETURN result
)
RETURN calcsjarilomkm_0-1647422724369.png

 

Appreciate any help. 

 

Kind regards,

JL

2 REPLIES 2
v-jinweili-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous ,

 

According my understanding, you want to sort article_count by each label and country.

If so, please create a measure:

 

measure = 
RANKX (
    FILTER (
        ALL ( 'planned_and_purchased' ),
        'planned_and_purchased'[Label ID] = MAX ( 'planned_and_purchased'[Label ID] )
            && 'planned_and_purchased'[country] = MAX ( 'planned_and_purchased'[country] )
    ),
    CALCULATE ( SUM ( planned_and_purchased[article_count] ) ),
    ,
    DESC,
    DENSE
)

 

Output:

vjinweilimsft_0-1647597997485.png

 

If not, please share more information (tables, outputs) to help us clarify your scenario. Or share me with your pbix file after removing sensitive data.

 

Refer to:

How to provide sample data in the Power BI Forum - Microsoft Power BI Community

How to Get Your Question Answered Quickly - Microsoft Power BI Community

 

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

PaulDBrown
Community Champion
Community Champion

Please provide sample data





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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