Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Remove Duplicates Per Group (keep first) measure help

Hi All   Is it possible to create a measure in PBI that remove duplicate values per group, and keeps the first occurrence of the value? Perhaps not a measure but maybe a new table, I'm unsure of ho...
  • Anonymous's avatar
    Anonymous
    6 years ago

    Here's the M code that does what you want:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKi1OLXJU0lEyBOLSvMzk/KI8ICstMTMHJGhgZWRsZWigFKuDUGkEks8vSi0uATIKEouLIQqNDaxMLFEU4jISVaUTTpXGViZA+40wVALliyqR7AaqM7YyBZoYCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [User = _t, EntryID = _t, Entry = _t, Status = _t, Time = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"User", type text}, {"EntryID", Int64.Type}, {"Entry", type text}, {"Status", type text}, {"Time", type time}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "FirstTimeEntry", 
            each List.Min( 
                Table.SelectRows(
                    #"Changed Type",
                    (r) => r[User] = [User] and r[Entry] = [Entry]
                )[Time] 
            ) = [Time]),
        #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([FirstTimeEntry] = true)),
        #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"FirstTimeEntry"})
    in
        #"Removed Columns"

     

    Best

    D