Forum Discussion

salfa_an's avatar
salfa_an
New Member
3 years ago
Solved

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

Here is my dummy table Product Returned Sequence Number Price Rank   wanted Rank A 1 121 400€ 1   1 A 2 150 0€       A 3 892 0€       A 4 563 0€       ...
  • OwenAuger's avatar
    3 years ago

    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