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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
mboulos11
New Member

Indexing based on two columns

Hello guys,

I have this table in power query, and I need to do indexing based on "UnitID" & "Attribute" columns.

1.PNGCapture.PNG

 

I want to index to start every time the Attribute is equal to "Installer", then start from the beginning everytime the UnitID is changed. For example:

UnitIDAttributeValue

Index

dslk322InstallerTeam 11
dslk322RoomLivingroom1
dslk322......1
dslk322......1
dslk322InstallerTeam 22
dslk322RoomBedroom 12
dslk322......2
dslk322......2
lkj32091InstallerTeam 21
lkj32091RoomBedroom 11
lkj32091......1
lkj32091......1

 

Can you help me pls?

1 ACCEPTED SOLUTION
Jakinta
Solution Sage
Solution Sage

You can try with steps below after the step your table looks like on an image.

 

Jakinta_0-1680297347188.png

 

 

let
    #"Added Index" = Table.AddIndexColumn( PreviousStepName, "Index", 0, 1, Int64.Type),
    Custom1 = Table.AddColumn(#"Added Index", "Extra_Index", each if [Index] = 0 then 1 else if #"Added Index"{[Index]}[Attribute] = "Installer" then 1 else 0),
    Grouped = Table.RemoveColumns ( Table.Group(Custom1, {"UnitID"}, {{"A", each  Table.FromColumns (Table.ToColumns(_) & {List.Skip(List.Accumulate(_[Extra_Index],{-1}, (s , c) => s & {List.Last(s) + c }))}, Table.ColumnNames(_) &{"i"}), type table }}), {"UnitID"} ),
    Expanded = Table.ExpandTableColumn (Grouped, "A", Table.ColumnNames ( Grouped [A]{0})),
    FINAL = Table.RemoveColumns(Expanded,{"Index", "Extra_Index"})
in
    FINAL

 

View solution in original post

1 REPLY 1
Jakinta
Solution Sage
Solution Sage

You can try with steps below after the step your table looks like on an image.

 

Jakinta_0-1680297347188.png

 

 

let
    #"Added Index" = Table.AddIndexColumn( PreviousStepName, "Index", 0, 1, Int64.Type),
    Custom1 = Table.AddColumn(#"Added Index", "Extra_Index", each if [Index] = 0 then 1 else if #"Added Index"{[Index]}[Attribute] = "Installer" then 1 else 0),
    Grouped = Table.RemoveColumns ( Table.Group(Custom1, {"UnitID"}, {{"A", each  Table.FromColumns (Table.ToColumns(_) & {List.Skip(List.Accumulate(_[Extra_Index],{-1}, (s , c) => s & {List.Last(s) + c }))}, Table.ColumnNames(_) &{"i"}), type table }}), {"UnitID"} ),
    Expanded = Table.ExpandTableColumn (Grouped, "A", Table.ColumnNames ( Grouped [A]{0})),
    FINAL = Table.RemoveColumns(Expanded,{"Index", "Extra_Index"})
in
    FINAL

 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

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.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.