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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
JamesBurke
Helper III
Helper III

Rank

Hi All , 

 

I have a Ranking system : 

 

 

Rank = 
VAR _RANK =
RANKX(FILTER(ALL('Emporia Devices'[Wawrick Device Name]) , 'Emporia Devices'[Wawrick Device Name] <> BLANK()), [Total solar Generated],,DESC,Dense)
RETURN
IF(
    MAX('Emporia Devices'[Wawrick Device Name]) <> BLANK(),
    _RANK,
    BLANK()
)

 

 

However when i have stores that are the same Rank for example : 

 

Store NameRankUsages
Store 1 115
Store 2210
Store 3210

 

I would like it to Rank based of Store name is Alphabetical order as decider so it would be : 

 

Store NameRankUsages
Store 1 115
Store 2210
Store 3310

 

Any Help would be appericated , 

 

Thanks , James. 

1 ACCEPTED SOLUTION
v-jianpeng-msft
Community Support
Community Support

Thank you OwenAuger and SamWiseOwl 

Hi, @JamesBurke 

Based on your descriptive information, as well as the example data provided and the expected output, I created the following example data:

vjianpengmsft_0-1723101997023.png

I created a measure using this DAX expression below:

Rank = 
VAR _rank =
    RANK (
        FILTER (
            ALLSELECTED ( 'Emporia Devices' ),
            'Emporia Devices'[Wawrick Device Name] <> BLANK ()
        ),
        ORDERBY (
            CALCULATE ( SUM ( 'Emporia Devices'[Total Solar Generated] ) ), DESC,
            CALCULATE ( MAX ( 'Emporia Devices'[Store Name] ) ), ASC
        )
    )
RETURN
    IF (
        SELECTEDVALUE ( 'Emporia Devices'[Wawrick Device Name] ) <> BLANK (),
        _rank,
        BLANK ()
    )

The results are as follows:

vjianpengmsft_1-1723102085696.png

I have provided the PBIX file used in this instance below.

 

 

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

10 REPLIES 10
Thennarasu_R
Responsive Resident
Responsive Resident

Hi @JamesBurke 

Good Day !

For your requirement you can use rankx function with caluculated column . below I have mention the Formulas for your requirements

Thennarasu_R_0-1723623642465.png

Thanks ,

Thennarasu R

SachinNandanwar
Continued Contributor
Continued Contributor

You can also use ROWNUMBER which is one of my faviorties to handle these kind of conditions

CustomRank = 
ROWNUMBER(FILTER(ALL('Emporia Devices') , 'Emporia Devices'[Wawrick Device Name] <> BLANK()),ORDERBY('Emporia Devices'[Store Name],ASC))






Regards,
Sachin
Check out my Blog
v-jianpeng-msft
Community Support
Community Support

Thank you OwenAuger and SamWiseOwl 

Hi, @JamesBurke 

Based on your descriptive information, as well as the example data provided and the expected output, I created the following example data:

vjianpengmsft_0-1723101997023.png

I created a measure using this DAX expression below:

Rank = 
VAR _rank =
    RANK (
        FILTER (
            ALLSELECTED ( 'Emporia Devices' ),
            'Emporia Devices'[Wawrick Device Name] <> BLANK ()
        ),
        ORDERBY (
            CALCULATE ( SUM ( 'Emporia Devices'[Total Solar Generated] ) ), DESC,
            CALCULATE ( MAX ( 'Emporia Devices'[Store Name] ) ), ASC
        )
    )
RETURN
    IF (
        SELECTEDVALUE ( 'Emporia Devices'[Wawrick Device Name] ) <> BLANK (),
        _rank,
        BLANK ()
    )

The results are as follows:

vjianpengmsft_1-1723102085696.png

I have provided the PBIX file used in this instance below.

 

 

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 @SachinNandanwar , @v-jianpeng-msft  , @SamWiseOwl  , @OwenAuger  

 

Thanks for the quick responses , for some reason on my end these Return Blank ? 

 

I have tried all of them and they come back blank , guessing it's something on my end ? 

 

Not sure . 

 

Thanks , James

Hi, @JamesBurke 

Thank you for your reply. Can you adjust the DAX expression provided above to suit your data set requirements? In your report, there may be different contexts that affect the rank results.
In the DAX expression I provided, the primary and secondary sorts are mainly implemented through ORDERBY.
The first parameter is the primary sorting basis: 'Emporia Devices'[Total Solar Generated]
The third parameter implements the secondary sorting (based on the sorting of one parameter): 'Emporia Devices'[Store Name]
In this way, Store can be considered when sorting Usages.

vjianpengmsft_0-1723606128144.png

 

 

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 , 

 

Was a case of changing all selected from the entire Table to the specfic column so it was all selected. 

 

Thanks for your response. 

 

James. 

Hi, @JamesBurke 

Have you solved the current problem? If yes, you can mark the helpful reply as a solution so that others in the community can find the answer quickly. If no, can you continue to describe your dataset in detail or provide some sample PBIX files that are closest to your situation and do not contain privacy?

 

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.

SamWiseOwl
Memorable Member
Memorable Member

Hi @JamesBurke 

 

Modified Rank =
var _sales = [Total solar Generated]
VAR _RANK =
RANKX(FILTER(ALL('Emporia Devices'[Wawrick Device Name]) , 'Emporia Devices'[Wawrick Device Name] <> BLANK()), [Total solar Generated],,DESC,Skip)
--var _test = RANKX(all('Emporia Devices'),[Wawrick Device Name],,DESC)
var matches = RANK(DENSE,FILTER(ALL('Emporia Devices'), [Total solar Generated] = _sales),ORDERBY([Wawrick Device Name]))

RETURN
IF(
    HASONEVALUE('Emporia Devices'[Wawrick Device Name]) ,
  _RANK+ ( matches-1),
    BLANK()
)
First calculate and store the current sales.
Then do the rank as normal using SKIP to create gaps.
Rank again but only items that have the same sales as the current row.
Add this secondary rank onto the first rank less 1.

If you are happy with this answer please mark as a solution for others to find !

Kudos are always appreciated! Check out our free Power BI video courses.

OwenAuger
Super User
Super User

Hi @JamesBurke 

The RANK function is useful when you need to break ties like this.

Here is a suggested version of your measure using RANK and rewritten slightly:

Rank = 
VAR SourceTable =
    ADDCOLUMNS (
        FILTER (
            ALL ( 'Emporia Devices'[Wawrick Device Name] ),
            NOT ISBLANK ( 'Emporia Devices'[Wawrick Device Name] )
        ),
        "@TotalSolarGenerated", [Total solar Generated]
    )
VAR _Rank =
    RANK (
        DENSE,
        SourceTable,
        ORDERBY (
            [@TotalSolarGenerated], DESC,
            'Emporia Devices'[Wawrick Device Name], ASC
        )
    )
RETURN
    IF (
        NOT ISBLANK ( MAX ( 'Emporia Devices'[Wawrick Device Name] ) ),
        _Rank
    )

 

Does this work at your end?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

@OwenAuger you beat me to it and with much neater code, nice one!

lol 24 seconds:

SamWiseOwl_0-1722950586580.png

 


If you are happy with this answer please mark as a solution for others to find !

Kudos are always appreciated! Check out our free Power BI video courses.

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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

Top Solution Authors
Top Kudoed Authors