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
bml123
Post Patron
Post Patron

Rank by date for each client Power Query

Hi,

 

I have data like this and need to add a rank column to order by date in descending order for each client.

How do I achieve this?

 

ClientDateRank
A01/02/20211
A09/09/20213
A15/05/20212
B20/01/20222
B07/02/20223
B19/11/20211
1 ACCEPTED SOLUTION
v-henryk-mstf
Community Support
Community Support

Hi @bml123 ,

 

Try formula like below:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vcy7CQAhEIThXjYW5gFyGHptiP23cRssJ8JEH/yzVsxoQYGGacVuRQO5i9TBfuhNMpFtkn/iU1+HNCBVuD8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Client = _t, Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Client", type text}, {"Date", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Client"}, {{"AllRowsGroups", each Table.AddIndexColumn(Table.Sort(_,{{"Date", Order.Ascending}}), "Row Rank",1,1), type table [Client=nullable text, 
                        Date=nullable text,
                        Row Rank=nullable number]}}),
    #"Expanded AllRowsGroups" = Table.ExpandTableColumn(#"Grouped Rows", "AllRowsGroups", {"Date", "Row Rank"}, {"Date", "Row Rank"})
in
    #"Expanded AllRowsGroups"

vhenrykmstf_0-1659694627334.png

 

For more, you can read below blog:

Adding a row rank based on a different column with Power Query – data witches (data-witches.com)

 

If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-henryk-mstf
Community Support
Community Support

Hi @bml123 ,

 

Try formula like below:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vcy7CQAhEIThXjYW5gFyGHptiP23cRssJ8JEH/yzVsxoQYGGacVuRQO5i9TBfuhNMpFtkn/iU1+HNCBVuD8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Client = _t, Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Client", type text}, {"Date", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Client"}, {{"AllRowsGroups", each Table.AddIndexColumn(Table.Sort(_,{{"Date", Order.Ascending}}), "Row Rank",1,1), type table [Client=nullable text, 
                        Date=nullable text,
                        Row Rank=nullable number]}}),
    #"Expanded AllRowsGroups" = Table.ExpandTableColumn(#"Grouped Rows", "AllRowsGroups", {"Date", "Row Rank"}, {"Date", "Row Rank"})
in
    #"Expanded AllRowsGroups"

vhenrykmstf_0-1659694627334.png

 

For more, you can read below blog:

Adding a row rank based on a different column with Power Query – data witches (data-witches.com)

 

If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Avantika-Thakur
Solution Supplier
Solution Supplier

Hi @bml123 ,

You can try applying the steps mentioned in this link - https://blog.crossjoin.co.uk/2015/05/11/nested-calculations-in-power-query/

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.