Forum Discussion

vedran's avatar
vedran
Frequent Visitor
8 years ago
Solved

New row based on previous row, ideas?

Hi there, I would like just ask for ideas.. have a transaction details table, and all details are in proper format expect 2 columns (Option and OptionAmount), goes like this:   TransDate | Customer...
  • MarcelBeug's avatar
    8 years ago

    Something like this:

     

    let
        Source = TransactionDetails,
        #"Added Custom" = Table.AddColumn(Source, "ProductOptions", each Text.Split([Product]&","&[Option],","), type {text}),
        #"Expanded ProductList" = Table.ExpandListColumn(#"Added Custom", "ProductOptions"),
        #"Added Index" = Table.AddIndexColumn(#"Expanded ProductList", "Index", 0, 1),
        #"Merged Queries" = Table.NestedJoin(#"Added Index",{"ProductOptions"},PriceList,{"Option"},"PriceList",JoinKind.LeftOuter),
        #"Expanded PriceList" = Table.ExpandTableColumn(#"Merged Queries", "PriceList", {"Price"}, {"PriceList.Price"}),
        #"Sorted Rows" = Table.Sort(#"Expanded PriceList",{{"Index", Order.Ascending}}),
        #"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"Index"}),
        #"Added Custom1" = Table.AddColumn(#"Removed Columns", "NewAmount", each if [Product] = [ProductOptions] then [Amount] else [PriceList.Price], type number),
        #"Removed Columns1" = Table.RemoveColumns(#"Added Custom1",{"Product", "Amount", "Option", "OptionAmount", "Sum", "PriceList.Price"}),
        #"Renamed Columns" = Table.RenameColumns(#"Removed Columns1",{{"ProductOptions", "Product"}, {"NewAmount", "Amount"}})
    in
        #"Renamed Columns"