Forum Discussion

dogburalHK82's avatar
dogburalHK82
Helper III
3 years ago
Solved

merge multiple rows with condition

Hi,    I have a raw table from ERP and they are multiple rows having the same PO no. as well as part number (or PO line no.).  Now I would like to merge those into one single row, I wonder how I c...
  • AlienSx's avatar
    3 years ago

    Hello, dogburalHK82 if you need the very last record per each PO and item then try this

    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        idx = Table.AddIndexColumn(Source, "idx", 1, 1, Int64.Type),
        f = (t as table) as record => Record.RemoveFields(Table.Last(Table.Sort(t, "idx")), "idx"),
        group = Table.Group(idx, {"Purchase Order", "Item Number"}, {{"all", each f(_), type table [idx=number]}}),
        z = Table.FromRecords(group[all])
    in
        z