Forum Discussion

Gcsingh149's avatar
Gcsingh149
New Member
3 years ago
Solved

Max date Keeping Ids Fixed

My first time with power query.


In power query I am trying to create a New column where it is only taking the max date per project ID i.e., keeping the Project ID fixed

 

IDDateDesired_Column
234561Null06/04/2023
234561Null06/04/2023
234561Null06/04/2023
234561Null06/04/2023
234561Null06/04/2023
234561Null06/04/2023
234561Null06/04/2023
234561Null06/04/2023
234561Null06/04/2023
234561Null06/04/2023
234561Null06/04/2023
234561Null06/04/2023
234561Null06/04/2023
234561Null06/04/2023
23456108/03/202306/04/2023
23456105/04/202306/04/2023
23456106/04/202306/04/2023
23456106/04/202306/04/2023
23456106/04/202306/04/2023
  • Hi Gcsingh149,

     

    Give this a go.

     

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjI2MTUzVNJRAiIDM10DE10jY6VYnVEJ6koYWOgaGINEcSowhYriVGBGEwWxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t, Desired_Column = _t]),
        ChType = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Desired_Column", type date}}),
        GroupRows = Table.Group(ChType, {"ID"}, {{"t", each List.Transform( [Date], (x)=> List.Max([Date])), type list}}),
        Expand = Table.ExpandListColumn(GroupRows, "t")
    in
        Expand

     

     

    with this result

     

    I hope this is helpful

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Gcsingh149 ,

    Please try.

    List.Max( Table.SelectRows( PreviousStepName, (x) => x[ID] = [ID])[Date] )

     

    all steps.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjI2MTUzVNJRUorVGfI8AwtdA2NdI2OEqBFI1FTXwART1Axd1JAI0VgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Date", type date}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Max Date", each List.Max( Table.SelectRows( #"Changed Type", (x) => x[ID] = [ID])[Date] ))
    in
        #"Added Custom"

     

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

2 Replies

  • m_dekorte's avatar
    m_dekorte
    Resident Rockstar

    Hi Gcsingh149,

     

    Give this a go.

     

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjI2MTUzVNJRAiIDM10DE10jY6VYnVEJ6koYWOgaGINEcSowhYriVGBGEwWxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t, Desired_Column = _t]),
        ChType = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Desired_Column", type date}}),
        GroupRows = Table.Group(ChType, {"ID"}, {{"t", each List.Transform( [Date], (x)=> List.Max([Date])), type list}}),
        Expand = Table.ExpandListColumn(GroupRows, "t")
    in
        Expand

     

     

    with this result

     

    I hope this is helpful

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Gcsingh149 ,

    Please try.

    List.Max( Table.SelectRows( PreviousStepName, (x) => x[ID] = [ID])[Date] )

     

    all steps.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjI2MTUzVNJRUorVGfI8AwtdA2NdI2OEqBFI1FTXwART1Axd1JAI0VgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Date", type date}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Max Date", each List.Max( Table.SelectRows( #"Changed Type", (x) => x[ID] = [ID])[Date] ))
    in
        #"Added Custom"

     

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum