Forum Discussion
SubodhPatra
4 years agoFrequent Visitor
Replace duplicate actions value except the first item for a user
Hi, I am new to Power Query and got stucked to transform the data in Actions column for duplicate entries except the first one. The data is as follows Mobile Number Actions Date 91919191...
- 4 years ago
Hi Vijay,
Many many thanks from the bottom of my heart!
The code is working fine and I was eagerly waiting for your reply.
Really, you are a "Super User".
With Regards,
Subodh
Vijay_A_Verma
Most Valuable Professional
4 years agoHere it is
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WsjREQCUdpcy8zJLMxJz4zJLU3GIg38hA16s0R9fISClWB0NxTmZ2KiE1GAaaEmEgMWosSbDUTNexNJ1YBxLhY0sqm2dkhMNAIyJC2YgUS8k1EFcIIpmHUBILAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Mobile Number" = _t, Actions = _t, Date = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Mobile Number", type text}, {"Actions", type text}, {"Date", type date}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
#"Grouped Rows" = Table.Group(#"Added Index", {"Mobile Number"}, {{"AllRows", each _}}),
fxProcess=(Tbl)=>
let
#"Filtered Rows" = Table.SelectRows(Tbl, each ([Actions] = "initial_items")),
#"Removed Top Rows" = Table.Skip(#"Filtered Rows",1),
#"Merged Queries" = Table.NestedJoin(Tbl, {"Index"}, #"Removed Top Rows", {"Index"}, "Removed Top Rows", JoinKind.LeftOuter),
#"Expanded Removed Top Rows" = Table.ExpandTableColumn(#"Merged Queries", "Removed Top Rows", {"Index"}, {"Index.1"}),
Custom2 = Table.ReplaceValue(#"Expanded Removed Top Rows",each [Actions],each if [Index.1] <> null then "more_items" else [Actions],Replacer.ReplaceValue,{"Actions"}),
#"Removed Columns" = Table.RemoveColumns(Custom2,{"Index.1"})
in
#"Removed Columns",
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each fxProcess([AllRows])),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"AllRows"}),
#"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Actions", "Date", "Index"}, {"Actions", "Date", "Index"}),
#"Sorted Rows" = Table.Sort(#"Expanded Custom",{{"Index", Order.Ascending}}),
#"Removed Columns1" = Table.RemoveColumns(#"Sorted Rows",{"Index"})
in
#"Removed Columns1"
👍 It's been a pleasure to help you | Help Hours: 11 AM to 9 PM (UTC+05:30)
How to get your questions answered quickly -- How to provide sample data
SubodhPatra
4 years agoFrequent Visitor
Hi Vijay,
Many many thanks from the bottom of my heart!
The code is working fine and I was eagerly waiting for your reply.
Really, you are a "Super User".
With Regards,
Subodh