Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Using Group-By based on MAX date column

Hello everybody,   I am trying to use the Group-By function in the PowerQuery but I am facing some issues. I have data that looks somewhat like the table below, and I would like to only keep the ro...
  • Jakinta's avatar
    Jakinta
    5 years ago

    This should work

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bY8xC8JADIX/ynFzhbvr5KgFQRAd6iKlw1FDKZakJop/30unq/aRIQnvIy9NY73KFtb5TarggjNJaVEN3I2g3Rk+5kb8SO1lArRt8Y/5bQYtmWokgftMBdWCSkP9fEdWpo5oDhxRBukozUc0E1PPILJKB5fTe5IXYZ4x95fq96v+LF+pyi8oceUhYj9/dSIxO+xhBPnN134B", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [CountryCustomerCode = _t, #"Date (B)" = _t, Name = _t, #"Current city" = _t, #"Status " = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date (B)", type date}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"CountryCustomerCode"}, {{"AA", each let t =_ in Table.SelectRows(t, each [#"Date (B)"] = List.Max(t[#"Date (B)"])), type table }}),
        #"Expanded AA" = Table.ExpandTableColumn(#"Grouped Rows", "AA", {"Date (B)", "Name", "Current city", "Status "}, {"Date (B)", "Name", "Current city", "Status "})
    in
        #"Expanded AA"

     

    My advice is to avoid spaces in ColumnNames and Step/TableNames, otherwise you have to use #"".

  • Anonymous's avatar
    Anonymous
    5 years ago

    Thank you very much, it seems to work!