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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
AndrewPF
Helper V
Helper V

ranking dates in Power Query

If I have the following in a table:

 

date
01/09/21
01/09/21
01/10/21
01/10/21
01/10/21
01/11/21
01/11/21
01/11/21
01/11/21
01/12/21
01/12/21
01/12/21
01/01/22
01/01/22

 

and I need to get to the following:

 

date             index
01/09/21         1
01/09/21         1
01/10/21         2
01/10/21         2
01/10/21         2
01/11/21         3
01/11/21         3
01/11/21         3
01/11/21         3
01/12/21         4
01/12/21         4
01/12/21         4
01/01/22         5
01/01/22         5

 

can I do it in Power Query?

 

The number of rows for each date is not fixed, and I have other columns in my table which I need to preserve.

 

1 ACCEPTED SOLUTION
v-luwang-msft
Community Support
Community Support

Hi @AndrewPF ,

Pls refer the below:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDUN7DUNzJUitXB5BgaEMcxJINjpK+AwsPBASIjIzROLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Date"}, {{"Count", each _, type table [Date=nullable date]}}),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1, Int64.Type),
    #"Expanded Count" = Table.ExpandTableColumn(#"Added Index", "Count", {"Date"}, {"Count.Date"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Count",{"Count.Date"})
in
    #"Removed Columns"

Before:

vluwangmsft_0-1648546790874.png

 

After:

vluwangmsft_1-1648546804259.png

 

You could download my pbix file if you need.

Did I answer your question? Mark my post as a solution!


Best Regards

Lucien

View solution in original post

6 REPLIES 6
rezadp
New Member

You could always add a table in Power Query with a distinct list of dates and then add the index.  Merge your table with the distinct list and return the index column...at least you know the data is persisted and you won't experience weird behaviour with calculated columns and filter context.

rezadp_0-1648752470253.png

 

v-luwang-msft
Community Support
Community Support

Hi @AndrewPF ,

Pls refer the below:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDUN7DUNzJUitXB5BgaEMcxJINjpK+AwsPBASIjIzROLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Date"}, {{"Count", each _, type table [Date=nullable date]}}),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1, Int64.Type),
    #"Expanded Count" = Table.ExpandTableColumn(#"Added Index", "Count", {"Date"}, {"Count.Date"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Count",{"Count.Date"})
in
    #"Removed Columns"

Before:

vluwangmsft_0-1648546790874.png

 

After:

vluwangmsft_1-1648546804259.png

 

You could download my pbix file if you need.

Did I answer your question? Mark my post as a solution!


Best Regards

Lucien

HotChilli
Super User
Super User

'Group By' using date with 'all rows' as aggregation.

Add Index column.

Expand All column to bring back fields

johnt75
Super User
Super User

Not sure if you can do that in Power Query but in DAX you could use RANKX, e.g.

Ranking = RANKX( 'Table', 'Table'[Date],, ASC, Dense)

Hi JohnT, 

I tried it but I keep getting the messge: "a single value for column 'Date' in table '[table name]' cannot be determined.  

Any idea? 

It needs to be a column not a measure

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.