Forum Discussion
WencyREN
4 years agoFrequent Visitor
Flag first occurrence item in Power Query
Dear, I have a sample dataset as shown below, could you please instruct me on how to add a custom column to flag the first occurrence of the product type (as 1, else as 0) in the Power Query environm...
- 4 years ago
This can help.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUYqIiEAhY3VIF3fCIe5MorgLieKk2ovVnFgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Product = _t, XXX = _t, XXX.1 = _t, XXX.2 = _t]), #"Added Custom" = Table.AddColumn(Source, "Custom", each List.PositionOf( Source[Product], [Product]) ), #"Added Index" = Table.AddIndexColumn(#"Added Custom", "Index", 0, 1, Int64.Type), #"Added Custom1" = Table.AddColumn(#"Added Index", "Flag", each Number.From([Custom]=[Index])), #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Custom", "Index"}) in #"Removed Columns"
mikekim123
3 years agoFrequent Visitor
is it possible to get the last occurence flag using any similar method