Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Hello guys,
I have this table in power query, and I need to do indexing based on "UnitID" & "Attribute" columns.
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:
| UnitID | Attribute | Value | Index |
| dslk322 | Installer | Team 1 | 1 |
| dslk322 | Room | Livingroom | 1 |
| dslk322 | ... | ... | 1 |
| dslk322 | ... | ... | 1 |
| dslk322 | Installer | Team 2 | 2 |
| dslk322 | Room | Bedroom 1 | 2 |
| dslk322 | ... | ... | 2 |
| dslk322 | ... | ... | 2 |
| lkj32091 | Installer | Team 2 | 1 |
| lkj32091 | Room | Bedroom 1 | 1 |
| lkj32091 | ... | ... | 1 |
| lkj32091 | ... | ... | 1 |
Can you help me pls?
Solved! Go to Solution.
You can try with steps below after the step your table looks like on an image.
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
You can try with steps below after the step your table looks like on an image.
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
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 2 |
| User | Count |
|---|---|
| 8 | |
| 6 | |
| 6 | |
| 6 | |
| 5 |