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
Evan_Power_Bi
Frequent Visitor

Numbering specific rows based on two columns

I am trying to use dax or a measure to do the following:
Using information that is similar to below I am trying to create a third column that numbers the rows based on the two columns.
ORDER     ORDER PART      

P0001           1

P0001           1

P0001           2

P0001           2

P0002           1

P0002           2

 

What I am looking to do:

 

ORDER     ORDER PART     LABEL

P0001           1                      1

P0001           1                       2

P0001           2                       1

P0001           2                       2

P0002           1                       1

P0002           2                       1

 

So if there are two P0001 that have ORDER PART "1" I want to number those rows from 1 to 2 so on and so forth. I am not trying to COUNT them. Thank you ahead of time for any help! I have been struggling on this one.

 

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

Hi @Evan_Power_Bi ,

You need to use  add index by group in power querey,refer:

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

vluwangmsft_0-1666856702173.png

 

Best Regards

Lucien

View solution in original post

3 REPLIES 3
v-luwang-msft
Community Support
Community Support

Hi @Evan_Power_Bi ,

You need to use  add index by group in power querey,refer:

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

vluwangmsft_0-1666856702173.png

 

Best Regards

Lucien

I think this is the solution I am looking for but I am not the most knowledgeable in the Custom Column in the Power Query. Can you provide some learning tools to use? I will try to input what you have given.

Hi  @Evan_Power_Bi ,

Do operations according the below links:

https://radacad.com/create-row-number-for-each-group-in-power-bi-using-power-query 

 

 

 

Best Regards

Lucien

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

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.