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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Everton
Helper I
Helper I

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

1 ACCEPTED SOLUTION

@Everton 
You mean like this?

1.png

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

View solution in original post

6 REPLIES 6
Everton
Helper I
Helper I

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

Everton_0-1676441518186.png

I really only want these records:

Everton_1-1676441544171.png

 

@Everton 
I fixed already in my original reply

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: 

Everton_0-1676441866936.png

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. 

@Everton 
You mean like this?

1.png

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

@tamerj1 , perfect thank you!

tamerj1
Super User
Super User

Hi @Everton 
Please refer to attached sample file with the solutin

1.png

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

 

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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