Forum Discussion
ahutchins
4 years agoFrequent Visitor
Increment index column based on another specific value
I have a dataset that includes an IncidentNumber, Responder, and ActionCode. Each responder is supposed to go through four ActionCodes, which I'll call Action 1-4, but some actions are skipped. Each ...
- 4 years ago
Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately)
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXIEYiOlWB0EzxiFZ4LCM0Th4dOHS84JxRQnFJVOOFQaoZhphGKmEYrLkFTGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Incident = _t, Responder = _t, Action = _t]), #"Grouped Rows" = Table.Group(Source, {"Incident", "Responder"}, {{"Temp", each _, type table [Incident=number, Responder=text, Action=number]}}), //Function Start fxProcessNext=(Tbl)=> let #"Added Index" = Table.AddIndexColumn(Tbl, "Index", 0, 1, Int64.Type), #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each try if Tbl[Action]{[Index]-1}>[Action] then "Y" else "N" otherwise "Y"), #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each List.Count(List.Select(List.FirstN(#"Added Custom"[Custom],[Index]+1), each _ = "Y"))), #"Renamed Columns" = Table.RenameColumns(#"Added Custom1",{{"Custom.1", "InstanceNum"}}) in #"Renamed Columns", //Function End #"Invoked Custom Function" = Table.AddColumn(#"Grouped Rows", "fxProcessNext", each fxProcessNext([Temp])), #"Expanded fxProcessNext" = Table.ExpandTableColumn(#"Invoked Custom Function", "fxProcessNext", {"Action", "InstanceNum"}, {"Action", "InstanceNum"}), #"Removed Columns" = Table.RemoveColumns(#"Expanded fxProcessNext",{"Temp"}) in #"Removed Columns"
Vijay_A_Verma
4 years agoMost Valuable Professional
Use this Excel file having the Query and output
- ahutchins4 years agoFrequent Visitor
Thank you so much! As it turns out, my version of Office (16) is too old. Fortunately, I'm a beta tester for 365 and it works great on that machine.