Forum Discussion

webportal's avatar
webportal
Icon for Impactful Individual rankImpactful Individual
5 years ago
Solved

Remove symmetrical records with Power Query

Is there a way to remove the yellow records with Power Query?

They are errors and I need to get rid of them:

 

The process could be something like:

  1. Filter the table to retrieve the rows containing only the current "CustomerID"
  2. Check the Sales. Is there any value with -Sales?

And then delete those rows.

 

This table contains many other Customer ID's - this is just a sample.

  • Hi webportal  ,


    According to you description, you could Use M language in power query, as follows:

    let
    
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"CustomerID", Int64.Type}, {"Sales", Int64.Type}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type", "Original", each Number.ToText([CustomerID]) &" "& Number.ToText( [Sales])),
    #"Added Custom" = Table.AddColumn(#"Added Custom1", "Opposite", each Number.ToText([CustomerID]) &" "& Number.ToText( [Sales]*-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"

    The final output is shown below:

    vs


    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.
    #End Reply 2nd

9 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi webportal 

     

    If I understand correctly, you also need to remove the two rows with 222,83 and -222,83 for this Customer ID in the sample? And the rows you want to remove are always together? Can you provide some sample data in a format we can copy?

    • webportal's avatar
      webportal
      Icon for Impactful Individual rankImpactful Individual

      Exactly Anonymous 

       

      No, the rows aren't always together, they can be far away.

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi webportal 

         

        I am asking do they appear as a pair like 222,83 and -222,83, or 222,83 can be far away with -222,83?

  • Hi,

    Your question is not clear.  Why should the rows showing 222.83 and -222.83 not be deleted as well?

  • v-yalanwu-msft's avatar
    v-yalanwu-msft
    Icon for Community Support rankCommunity Support

    Hi webportal  ,


    According to you description, you could Use M language in power query, as follows:

    let
    
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"CustomerID", Int64.Type}, {"Sales", Int64.Type}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type", "Original", each Number.ToText([CustomerID]) &" "& Number.ToText( [Sales])),
    #"Added Custom" = Table.AddColumn(#"Added Custom1", "Opposite", each Number.ToText([CustomerID]) &" "& Number.ToText( [Sales]*-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"

    The final output is shown below:

    vs


    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.
    #End Reply 2nd