Forum Discussion

evadung's avatar
evadung
Frequent Visitor
3 years ago

Day with latest time

Hello, 

I have this table. I want to have items with date and latest time. See example.

Any idea how to do it?

ItemDateAmount
A1.3.2023 15:031
A1.3.2023 9:318
A1.3.2023 6:004
A25.2.2023 7:555
A25.2.2023 6:043
B15.2.2023 16:117
B15.2.2023 11:003
B15.2.2023 15:001
C9.2.2023 12:235
C9.2.2023 9:563

 

=>

 

ItemDateAmount
A1.3.2023 15:031
A25.2.2023 7:555
B15.2.2023 16:117
C9.2.2023 12:235

2 Replies

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Community Champion

    NewStep=Table.FromRecords(Table.Group(PreviousStepName,"Item",{"n",each Table.Sort(_,{"Date",1}){0}})[n])

  • CNENFRNL's avatar
    CNENFRNL
    Community Champion

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bc7NDcAgCAbQVRrPxgiIVm5txzDuv0axJCZtvcH3wk9r7nDeQaCAEWkDlkgjcN1/qAqB9vtfssSofZqCHNCoCLMGvCCdShrQQ+fYNwmywLhVVgZ2bTnHZvb9pVWdhII0P3lRFc62sN8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Item = _t, Date = _t, Amount = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Item", type text}, {"Date", type datetime}, {"Amount", Int64.Type}}),
    
        #"Added Dt" = Table.AddColumn(#"Changed Type", "Dt", each Date.From([Date])),
        Grouped = Table.Group(#"Added Dt", "Dt", {"Grp", each Table.Max(_, "Date")}, 0),
        #"Expanded Grp" = Table.RemoveColumns(Table.ExpandRecordColumn(Grouped, "Grp", {"Item", "Date", "Amount"}), "Dt")
    in
        #"Expanded Grp"