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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Greg888
Helper I
Helper I

Add a column with steps based on number of entries in a column

I have a bit of strange problem, which would be easily solved in SQL using RowNumber and order by but I am looking for something similar in Power BI 

 

I have a document workflow but the steps in the workflow can vary from document to document, I just want to add a column to show how many steps the document has been through. Example of how I would like to 

Document NumberStep

001

1

0012
0013
0014
0021
0022
003

1

003

2

003

3

003

4

 

 

 

Etc... 

1 ACCEPTED SOLUTION

Hi, @Greg888 

You can try add index column within a Group with Power Query.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjAwMFSK1cHL8DEwMEJluBsYGONlxAIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Document Number" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Document Number", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
    #"Grouped Rows" = Table.Group(#"Added Index", {"Document Number"}, {{"Count", each _, type table [Document Number=nullable text, Index=number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Count],"Rank",1,1)),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Document Number", "Rank"}, {"Document Number", "Rank"})
in
    #"Expanded Custom"

1.png

For more details, please refer to this tutorial.

Ranking within a Group with Power Query 

 

Best Regards,
Community Support Team _ Eason

View solution in original post

4 REPLIES 4
Greg888
Helper I
Helper I

Perhaps I should have said the docnumbers contain Text so 

P001

L002

G003

for instance

 

I think this is what is causing the error

 

amitchandak
Super User
Super User

@Greg888 ,

first add an index column in power query 

https://stackoverflow.com/questions/45715963/creating-an-index-column-for-power-bi

 

then add a new column in dax

 

countx(filter(Table, [Document] =earlier([Document]  && [Index] <= earlier([Index]) ), [index] )

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Sadly it didn't work.


Steps = COUNTX(FILTER(DocStepSequence,DocStepSequence[DocNumber] = EARLIER(DocStepSequence,DocStepSequence[DocNumber] && DocStepSequence,DocStepSequence[DocNumber_ID] <= EARLIER(DocStepSequence,DocStepSequence[DocNumber_ID],DocStepSequence,DocStepSequence[DocNumber_ID])

 

too Many arguments passed to the FILTER functions 

Hi, @Greg888 

You can try add index column within a Group with Power Query.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjAwMFSK1cHL8DEwMEJluBsYGONlxAIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Document Number" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Document Number", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
    #"Grouped Rows" = Table.Group(#"Added Index", {"Document Number"}, {{"Count", each _, type table [Document Number=nullable text, Index=number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Count],"Rank",1,1)),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Document Number", "Rank"}, {"Document Number", "Rank"})
in
    #"Expanded Custom"

1.png

For more details, please refer to this tutorial.

Ranking within a Group with Power Query 

 

Best Regards,
Community Support Team _ Eason

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors