Forum Discussion
Power Query Editor: add increment step for each entry with the same ID
- 5 years ago
Anonymous
It's a minor variation on the previous version:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVtJRCkkszlYwBDKCS1ILFPISc1MVEpOSlWJ18ChITUvHr6CisgqswNQcrsAIRUFyUiJ+BSmpaWAFlhbmMAXGKAoyMrMgbjCwhCkwQVGQk5sHscIMboUpioK8/AL8CgqLisEKzM1MYQrMUBSUlJYpxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Task Name" = _t, #"Step Name" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Step", each Table.AddIndexColumn(_, "Step", 1, 1, Int64.Type)}}), #"Expanded Step" = Table.ExpandTableColumn(#"Grouped Rows", "Step", {"Task Name", "Step Name", "Step"}, {"Task Name", "Step Name", "Step"}), #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Step",{{"Task Name", type text}, {"Step Name", type text}, {"Step", Int64.Type}}), #"Added Custom" = Table.AddColumn(#"Changed Type1", "ID_Step", each Text.From([ID]) & "-" & Text.From([Step]), type text), #"Reordered Columns" = Table.ReorderColumns(#"Added Custom",{"ID", "Step", "ID_Step", "Task Name", "Step Name"}) in #"Reordered Columns"Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
- 5 years ago
Anonymous
You can create two calculated columns:
Step = CALCULATE ( COUNT ( Table1[Step Name] ), Table1[Step Name] <= EARLIER ( Table1[Step Name] ), ALLEXCEPT ( Table1, Table1[ID] ) )ID_Step = Table1[ID] & "-" & Table1[Step]Do note though that you, as it is now, you do not have a column to establish order in the table in DAX. You would either have to add an index at the source (like you'd do it in PQ) or a possible alternative would be to use Step Name to establish that order (alphabetically), which is what I have done here.
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
Anonymous
It's a minor variation on the previous version:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVtJRCkkszlYwBDKCS1ILFPISc1MVEpOSlWJ18ChITUvHr6CisgqswNQcrsAIRUFyUiJ+BSmpaWAFlhbmMAXGKAoyMrMgbjCwhCkwQVGQk5sHscIMboUpioK8/AL8CgqLisEKzM1MYQrMUBSUlJYpxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Task Name" = _t, #"Step Name" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Step", each Table.AddIndexColumn(_, "Step", 1, 1, Int64.Type)}}),
#"Expanded Step" = Table.ExpandTableColumn(#"Grouped Rows", "Step", {"Task Name", "Step Name", "Step"}, {"Task Name", "Step Name", "Step"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Expanded Step",{{"Task Name", type text}, {"Step Name", type text}, {"Step", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type1", "ID_Step", each Text.From([ID]) & "-" & Text.From([Step]), type text),
#"Reordered Columns" = Table.ReorderColumns(#"Added Custom",{"ID", "Step", "ID_Step", "Task Name", "Step Name"})
in
#"Reordered Columns"
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
This is great, thanks! Work Perfectly.
Is there a way to achieve the same result but by using a calculate column in DAX?
I have a DirectQuery data connection, with the same sample data where I also need to get the same result (but as its DirectQuery I cannot add columns using M in the editor - hope I have understood that right?)
Thank you for baring with me, I much appreciate your assistance.