Forum Discussion
rangeet1
4 years agoFrequent Visitor
Delete match negative and positive rows
I have ran into a problem where the purchase and refund are both shown in my data. I want to get rid of both matching values. Both vaues are under a unique Customer ID. Thank you
- 4 years ago
Hi, rangeet1 ;
Try it;
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8vAzMDBX0lFSUTA1UIrVQRYwQxcwRxewQBfQxTBEF2qKc6iBgQVYxAhdwBhdwARdwNAAXUQXLBQLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Customer ID" = _t, Amount = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Customer ID", type text}, {"Amount", type text}}), #"Replaced Value" = Table.ReplaceValue(#"Changed Type","$ ","",Replacer.ReplaceText,{"Amount"}), #"Changed Type1" = Table.TransformColumnTypes(#"Replaced Value",{{"Amount", Int64.Type}}), #"Added Custom" = Table.AddColumn(#"Changed Type1", "Original", each [Customer ID]&" "&Text.From([Amount])), #"Added Custom1" = Table.AddColumn(#"Added Custom", "Opposite", each [Customer ID]&" "&Text.From([Amount]*-1)), #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom.2", each if List.Contains(#"Added Custom"[Original],[Opposite]) then "" else 1), #"Filtered Rows" = Table.SelectRows(#"Added Custom2", each ([Custom.2] = 1)), #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Original", "Opposite", "Custom.2"}) in #"Removed Columns"The final output is shown below:
Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-yalanwu-msft
Community Support
4 years agoHi, rangeet1;
You could complete it in power query .
1.add custom column.
= Table.AddColumn(#"Changed Type", "Original", each Number.ToText([Customer ID]) &" "& Number.ToText( [Amount]))
2.add another custom column.
= Table.AddColumn(#"Added Custom1", "Opposite", each Number.ToText([Customer ID]) &" "& Number.ToText( [Amount]*-1))
3.add 3rd custom column.
= Table.AddColumn(#"Added Custom", "Flag", each if List.Contains(#"Added Custom"[Original],[Opposite]) then "" else 1)
4.filter rows.(1)
5.remove columns.
The final output is shown below:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwUNJRMjVQitWBccyQOebIHAtkji6KJl24LkMgzwiZY4zMMUHmgLQieLpgbiwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Customer ID" = _t, Amount = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Customer ID", Int64.Type}, {"Amount", Int64.Type}}),
#"Added Custom1" = Table.AddColumn(#"Changed Type", "Original", each Number.ToText([Customer ID]) &" "& Number.ToText( [Amount])),
#"Added Custom" = Table.AddColumn(#"Added Custom1", "Opposite", each Number.ToText([Customer ID]) &" "& Number.ToText( [Amount]*-1)),
#"Added Custom2" = Table.AddColumn(#"Added Custom", "Flag", each if List.Contains(#"Added Custom"[Original],[Opposite]) then "" else 1),
#"Filtered Rows" = Table.SelectRows(#"Added Custom2", each [Flag] <> null and [Flag] <> ""),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Original", "Opposite", "Flag"})
in
#"Removed Columns"
Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Syndicate_Admin
Administrator
4 years agoI have tried to follow these steps. However, the last step is taking a lot
of time to load.
Thanks