Forum Discussion

CoffeeCup1's avatar
CoffeeCup1
New Member
2 years ago
Solved

Move cell to new column in row below and delete row

Hello, I am new to PowerQuery; apologies if this is a simple quesiton.   I have rows of "invoice" data. The name of the vendor appears above every entry in its own row. Also, there is a "total" row...
  • ronrsnfld's avatar
    2 years ago

    If your data is really formed as you show, this code will produce your shown results:

    let
        Source = Excel.CurrentWorkbook(){[Name="Table5"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{
            {"Invoice Number", type text}, {"Invoice Date", type date}, {"Post Month", type date}, 
            {"Invoice Status", type text}, {"Payment/Check #", type text}, {"Due Date", type date}, 
            {"Amount", Currency.Type}}),
        #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
        #"Inserted Integer-Division" = Table.AddColumn(#"Added Index", "Integer-Division", each Number.IntegerDivide([Index], 3), Int64.Type),
        #"Removed Columns" = Table.RemoveColumns(#"Inserted Integer-Division",{"Index"}),
        #"Grouped Rows" = Table.Group(#"Removed Columns", {"Integer-Division"}, {
            {"all", (t)=>
            Table.FillUp(
            Table.AddColumn(t,"Vendor",each Splitter.SplitTextByDelimiter(": ")(t[Invoice Number]{0}){1}),
                List.RemoveItems(Table.ColumnNames(t),{"Payment/Check #"})){1}}
            }),
        #"Removed Columns1" = Table.RemoveColumns(#"Grouped Rows",{"Integer-Division"}),
        #"Expanded all" = Table.ExpandRecordColumn(#"Removed Columns1", "all", {"Vendor","Invoice Number", "Invoice Date", "Post Month", "Invoice Status", "Payment/Check #", "Due Date", "Amount"}),
        #"Transform Post Month" = Table.TransformColumns(#"Expanded all",{"Post Month", each Date.ToText(_,"M/yyyy")}),
        #"Changed Type1" = Table.TransformColumnTypes(#"Transform Post Month",{
            {"Vendor", type text}, {"Invoice Number", type text}, {"Invoice Date", type date}, 
            {"Invoice Status", type text}, {"Payment/Check #", type any}, 
            {"Due Date", type date}, {"Amount", Currency.Type}})
    in
        #"Changed Type1"

     

    Results from your posted data: