Forum Discussion

joooffice's avatar
joooffice
Helper I
5 years ago
Solved

Conditional Group by depending on value in another column

I have data that imports from two different sources - one has a unique identifer Account ID and one doesnt.  I need to group the data to allow me to do a comparison to see if there are any duplicati...
  • v-yingjl's avatar
    5 years ago

    Hi joooffice ,

    Based on the conditional group logic, you can group each source and combine them after it like this query(use the count number as the default group result):

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WClbSUTI0MjYBUh6JRUWVCiFFpbmJeUCukYGRob6ZvqGRUqwOpjrsCkwtzIGUU36Sgld+XmoxqYoswIqcfIFCCkDsl5mcrRCcm1mSgWEQSWo8UnNS83BbA5ZW8ErMRXdLLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Source = _t, #"Account ID" = _t, Name = _t, #"Service Date" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Source", type text}, {"Account ID", Int64.Type}, {"Name", type text}, {"Service Date", type date}}),
        #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Source] = "BM")),
        #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Source", "Name", "Service Date"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
        #"Filtered Rows2" = Table.SelectRows(#"Changed Type", each ([Source] = "S")),
        #"Grouped Rows1" = Table.Group(#"Filtered Rows2", {"Source", "Account ID", "Service Date"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
        #"Appended Query" = Table.Combine({#"Grouped Rows1", #"Grouped Rows"})
    in
        #"Appended Query"

     

    Best Regards,
    Community Support Team _ Yingjie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.