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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
salfa_an
New Member

How do I rank values within groups ignoring blanks/zero according to its returned sequence?

Here is my dummy table

ProductReturned SequenceNumberPriceRank wanted Rank
A1121400€1 1
A21500€   
A38920€   
A45630€   
A5892700€5 2
A58921000€5 2
A5892100€5 2
B1801100€1 1
B18015000€1 1
B26530€   
B3788300€3 2
B37880€   

 

I calculated the Rank Column with:

 

 

Rank = IF(Table1[Cost] <> 0, RANKX(FILTER(Table1, Table1[Product] = EARLIER(Table1[Product])), Table1[Returned Sequence],, ASC, Dense))


Is there any other formula/workaround to get the rank like in the wanted rank column? Thank you!

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @salfa_an 

Here are a couple of options:

 

1. Modify your original expression to ensure Cost <> 0 within FILTER:

Rank 2 =
IF (
    Table1[Cost] <> 0,
    RANKX (
        FILTER (
            Table1,
            Table1[Product]
                = EARLIER ( Table1[Product] )
                && Table1[Cost] <> 0
        ),
        Table1[Returned Sequence],
        ,
        ASC,
        DENSE
    )
)

 2. Rank over a table of distinct values of Returned Sequence, created using CALCULATETABLE:

Rank 3 = 
IF (
    Table1[Cost] <> 0,
    VAR RankingTable =
        CALCULATETABLE (
            VALUES ( Table1[Returned Sequence] ),
            ALLEXCEPT ( Table1, Table1[Product] ),
            Table1[Cost] <> 0
        )
    RETURN
        RANKX (
            RankingTable,
            Table1[Returned Sequence],
            ,
            ASC
        )
    )

 

Do these work for you?

Regards


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

View solution in original post

2 REPLIES 2
OwenAuger
Super User
Super User

Hi @salfa_an 

Here are a couple of options:

 

1. Modify your original expression to ensure Cost <> 0 within FILTER:

Rank 2 =
IF (
    Table1[Cost] <> 0,
    RANKX (
        FILTER (
            Table1,
            Table1[Product]
                = EARLIER ( Table1[Product] )
                && Table1[Cost] <> 0
        ),
        Table1[Returned Sequence],
        ,
        ASC,
        DENSE
    )
)

 2. Rank over a table of distinct values of Returned Sequence, created using CALCULATETABLE:

Rank 3 = 
IF (
    Table1[Cost] <> 0,
    VAR RankingTable =
        CALCULATETABLE (
            VALUES ( Table1[Returned Sequence] ),
            ALLEXCEPT ( Table1, Table1[Product] ),
            Table1[Cost] <> 0
        )
    RETURN
        RANKX (
            RankingTable,
            Table1[Returned Sequence],
            ,
            ASC
        )
    )

 

Do these work for you?

Regards


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

Hi @OwenAuger 
i tried your first solution and it works. thank you so much

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.