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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
martim0305
Frequent Visitor

Create conditional index column

Hello.

I want to create a new index column in power query that resets every time the value of anothe column changes.

 

It should look like this:

martim0305_0-1710860922803.png


In this case, every time a new colour appears, the index increases by one based on this column's value. Can you help me doing it in power query editor?

Thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @martim0305 ,

@Anonymous Thank you for your replying!

 

I agree it should use Group by function. And I tried to simplify the M function:

vjunyantmsft_1-1710901458029.png

And expand the table:

vjunyantmsft_2-1710901479662.png

The final output is as below:

vjunyantmsft_3-1710901502015.png

Here is the whole M function in the Advanced Editor:

 

 

 

 

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

 

 

 

 

 
Best Regards,
Dino Tao
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

3 REPLIES 3
Anonymous
Not applicable

Hi @martim0305 ,

@Anonymous Thank you for your replying!

 

I agree it should use Group by function. And I tried to simplify the M function:

vjunyantmsft_1-1710901458029.png

And expand the table:

vjunyantmsft_2-1710901479662.png

The final output is as below:

vjunyantmsft_3-1710901502015.png

Here is the whole M function in the Advanced Editor:

 

 

 

 

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

 

 

 

 

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

Thank you so much for replying. This reply really helped me out! Thank you for being so clear answering.

Anonymous
Not applicable

I would group by Coulour, and then add a custom column that applies an index to each grouped table. Then you can just expand the new custom column. So after grouping, something like

 

Table.AddColumn(PriorStepOrTableName, "Indexes", each Table.AddIndexColumn([Name of TableColumn], "Index", 1,1))


Delete the grouped table column, and expand your new table column. That's it!

 

--Nate

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.