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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
bml123
Post Patron
Post Patron

Group by id, category and rank by date

Hi,

I have data like this and need rank column like this, group by id , category and ordered by date. How do I achieve this?

 

IdDateAmountCategoryRank
101/01/202210A1
104/01/202215A2
128/01/202210A3
117/02/202220B1
125/03/202215B2
202/03/202210A1
219/03/202212A2
305/04/202250A1
429/05/202260B1
1 ACCEPTED SOLUTION
v-jayw-msft
Community Support
Community Support

Hi @bml123 ,

 

Please check the formula:

rankk =
RANKX (
    FILTER (
        'Table',
        'Table'[Id] = EARLIER ( 'Table'[Id] )
            && 'Table'[Category] = EARLIER ( 'Table'[Category] )
    ),
    'Table'[Date],
    ,
    ASC
)

vjaywmsft_0-1657523338977.png

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

4 REPLIES 4
v-jayw-msft
Community Support
Community Support

Hi @bml123 ,

 

Please check the formula:

rankk =
RANKX (
    FILTER (
        'Table',
        'Table'[Id] = EARLIER ( 'Table'[Id] )
            && 'Table'[Category] = EARLIER ( 'Table'[Category] )
    ),
    'Table'[Date],
    ,
    ASC
)

vjaywmsft_0-1657523338977.png

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
HotChilli
Super User
Super User

create another variable (similar to the first one but it will be on Category).

Add a condition to the FILTER to use the new variable (just like the existing one and use &&)  like 

Table[Id] = _id && Table[Cat....

Give it a go and I will help if you are stuck.

HotChilli
Super User
Super User

Something like this?

ColumnNew = var _id = TableV[Id]
RETURN
RANKX(FILTER(TableV, TableV[Id] = _id), TableV[Date],, ASC)

 

Hi @HotChilli ,

 

Thanks for this.  I also need to do group by by the category too.  I have edited and posted sample data for that. How do I add that condition in your formula?

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.