Forum Discussion

theo's avatar
theo
Helper III
7 years ago

Count duplicate values using switch or if statement

Hi.  I have been bugging witht this problem to count duplicates in multiple columns involving 12millions rows and counting.  I am trying now with the approach which does not provide me the correct result.

Basically what I need is to check how maany from in the table have 5 similar entries with the current table
Table has 6 columns, and duplicate number does not need to be in the same column.  As you can see my attemp below is to check only 1 duplicate (I checked only the first column agains 2 columns just to see if it works)

Any different approach involving measure is appreciated (calculated columns may either be slow or will result to memory issue).

Thanks.

=sumx(
'3_13May',
 if(sumx('3_13May',SWITCH (
        TRUE (),
        '3_13May'[Column1]=EARLIER('3_13May'[Column1]),1,
        '3_13May'[Column2]=EARLIER('3_13May'[Column1]),1,0))=1,1,0
))

6 Replies

  • Mariusz's avatar
    Mariusz
    Community Champion

    Hi theo 

    Can you send some data sample?

     

    Best Regards,
    Mariusz

    Please feel free to connect with me.
    Mariusz Repczynski

     

    • theo's avatar
      theo
      Helper III

      Hi Mariusz ;

      Here's a representative sample  and some manual calculations I did.

      • Mariusz's avatar
        Mariusz
        Community Champion

        Hi theo 

         

        You can achieve this by applying three steps in Query editor.

        Please see the M code below based on the example that you provided.

         

        let
            Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dY+xDcQwDAN3cZ0iEpnEmSXw/mu8zm4ej3xBwQB5lPw8LdrWsqSSS0fpbGN7d67p9HrdpdgZ5IJg6J8LHsdqpSZOxsUgHcRzf/NzXkF7rvbknKQwSSbJnMn+69MqjhAlyukLX/iCF7zg1b98UIMa1Oz32m9QgxrUoOYTvtsYHw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t]),
            #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", Int64.Type}, {"Column3", Int64.Type}, {"Column4", Int64.Type}, {"Column5", Int64.Type}, {"Column6", Int64.Type}}),
            #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {}, "Attribute", "Value"),
            #"Grouped Rows" = Table.Group(#"Unpivoted Columns", {"Value"}, {{"Count", each Table.RowCount(_), type number}}),
            #"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each ([Count] <> 1))
        in
            #"Filtered Rows"
        Best Regards,
        Mariusz

        If this post helps, then please consider Accepting it as the solution.

        Please feel free to connect with me.
        Mariusz Repczynski