Forum Discussion
Delete match negative and positive rows
- 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.
This is what i am looking for. Remove matching negative and positive amount
thank you
- Samarth_184 years ago
Community Champion
Hi rangeet1 ,
Create measure like this and use it as filter:-
Measure 4 = VAR amt = -1 * MAX('Table (5)'[Amount]) var cust_id = MAX('Table (5)'[Customer ID]) RETURN COUNTROWS ( FILTER ( ALL( 'Table (5)' ), 'Table (5)'[Amount] = amt && 'Table (5)'[Customer ID] = cust_id ) )Ouput:-
Thanks,
Samarth
- Ashish_Mathur4 years ago
Super User
Hi,
If you want to do this at the visual level, then simply drag Customer ID to the tabel visual and write this measure
Measure = sum(data[amount])
Apply a filter of >0
- rangeet14 years agoFrequent Visitor
thank you
But i still have the postive values in the data. with yourformula i can only eliminate the negative values. But i have the corresponding positive values that i want to delete as well.
- Ashish_Mathur4 years ago
Super User
Hi,
This M code works
let Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content], #"Changed Type" = Table.TransformColumnTypes(Source,{{"Customer ID", type text}, {"Amount", Int64.Type}}), #"Inserted Absolute Value" = Table.AddColumn(#"Changed Type", "Absolute Value", each Number.Abs([Amount]), Int64.Type), #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Inserted Absolute Value", {{"Absolute Value", type text}}, "en-IN"),{"Customer ID", "Absolute Value"},Combiner.CombineTextByDelimiter(";", QuoteStyle.None),"Merged"), #"Grouped Rows" = Table.Group(#"Merged Columns", {"Merged"}, {{"GroupTables", each _, type table [Amount=nullable number, Merged=text]}}), #"Added Custom" = Table.AddColumn(#"Grouped Rows", "CountRows", each Table.RowCount([GroupTables])), #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([CountRows] = 1)), #"Split Column by Delimiter" = Table.SplitColumn(#"Filtered Rows", "Merged", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Merged.1", "Merged.2"}), #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Merged.1", Int64.Type}, {"Merged.2", Int64.Type}}), #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"GroupTables", "CountRows"}), #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Merged.1", "Customer ID"}, {"Merged.2", "Amount"}}), #"Changed Type2" = Table.TransformColumnTypes(#"Renamed Columns",{{"Customer ID", type text}}) in #"Changed Type2"Hope this helps.