Forum Discussion

Everton's avatar
Everton
Helper I
3 years ago
Solved

Rank within group

Hi,

I want to rank within a group. First group by Id then rank by MostRecentUpdate. This is how I want the data to look. 

IdInvoiceNumberInvoiceDateInvoiceStatusOwingMostRecentUpdateRank
1aaae1ed-2c74-ed11-ac20-d8e2df0c6786281085/12/2022 0:00Paid$04/12/2022 23:401
1aaae1ed-2c74-ed11-ac20-d8e2df0c6786281085/12/2022 0:00Unpaid$939.304/12/2022 23:392
8178e2a2-5240-ec11-981f-501ac52e327f100268/11/2021 0:00Paid$04/12/2022 23:531
8178e2a2-5240-ec11-981f-501ac52e327f100268/11/2021 0:00Part paid$121.408/11/2021 5:132
cdf5286c-2d74-ed11-ac20-d8e2df0c6786281125/12/2022 0:00Paid$04/12/2022 23:441
cdf5286c-2d74-ed11-ac20-d8e2df0c6786281125/12/2022 0:00Unpaid$1204/12/2022 23:432
de40fdc5-2e74-ed11-ac20-d8e2df0c6786281235/12/2022 0:00Paid$04/12/2022 23:531
de40fdc5-2e74-ed11-ac20-d8e2df0c6786281235/12/2022 0:00Unpaid$4104/12/2022 23:522
e0ea3584-cd74-ed11-ac20-d8e2df0c6786281416/12/2022 0:00Paid$05/12/2022 18:501
e0ea3584-cd74-ed11-ac20-d8e2df0c6786281416/12/2022 0:00Paid$05/12/2022 18:501
e0ea3584-cd74-ed11-ac20-d8e2df0c6786281416/12/2022 0:00Unpaid$1205/12/2022 18:492
e70bfa9d-2d74-ed11-ac20-d8e2df0c6786281155/12/2022 0:00Paid$04/12/2022 23:452
e70bfa9d-2d74-ed11-ac20-d8e2df0c6786281155/12/2022 0:00Paid$04/12/2022 23:531
e70bfa9d-2d74-ed11-ac20-d8e2df0c6786281155/12/2022 0:00Unpaid$151.504/12/2022 23:443
f08f6a2f-ce74-ed11-ac20-d8e2df0c6786281466/12/2022 0:00Paid$05/12/2022 18:541
f08f6a2f-ce74-ed11-ac20-d8e2df0c6786281466/12/2022 0:00Unpaid$323.205/12/2022 18:541


I have tried to do a measure, but it gives everything a rank of 1:

 

RankInGroupTest = 
VAR InvoiceId = SELECTEDVALUE(data[Id])
VAR FilteredInvoices = FILTER(ALL(data),data[Id] = InvoiceId)
RETURN RANKX(
    FilteredInvoices, CALCULATE(SELECTEDVALUE(data[Id])), , DESC, Dense
)

 


I have attached an example pbix file. This has to be a measure because I want the rank to be dynamic upon what the user has selected in the slicers. 


See example pbix: https://filebin.net/y5glwphpsdgcf1c2/Billing_Test.pbix

  • Everton 
    You mean like this?

    RankInGroupTest = 
    IF (
        NOT ISEMPTY ( data ),
        RANKX ( 
            CALCULATETABLE ( 
                data,
                ALLEXCEPT ( Data, data[ID] )
            ),
            CALCULATE ( SELECTEDVALUE ( data[MostRecentUpdate] ) ),, 
            DESC, 
            Dense
        )
    )

6 Replies

  • tamerj1's avatar
    tamerj1
    Community Champion

    Hi Everton 
    Please refer to attached sample file with the solutin

    IF (
        NOT ISEMPTY ( data ),
        RANKX ( 
            CALCULATETABLE ( 
                data,
                ALLEXCEPT ( Data, data[InvoiceDate] )
            ),
            CALCULATE ( SELECTEDVALUE ( data[Id] ) ) 
                & CALCULATE ( SELECTEDVALUE ( data[MostRecentUpdate] ) ),, 
                DESC, 
                Dense
        )
    )

     

     

     

  • Thanks for your help tamerj1 . Do you know why there are all these extra records appearing? 

    I really only want these records:

     

      • Everton's avatar
        Everton
        Helper I

        Thank you again tamerj1 . I was wanting to group by Id and rank within that group. I have tried to highlight the groups in the below image: 

        For example, withing the group with Id "e0ea3584-cd74-ed11-ac20-d8e2df0c6786" there should be rank 1,2,3. Rank 1 will be the latest MostRecentUpdate.