Results 1 to 2 of 2

Thread: VBA - Merge the results of summing two rows into an single row

  1. #1
    Neophyte Gregpen's Avatar
    Join Date
    Jan 2020
    Posts
    1
    Articles
    0
    Excel Version
    Office 365 Business

    VBA - Merge the results of summing two rows into an single row



    Register for a FREE account, and/
    or Log in to avoid these ads!

    I have a worksheet that I am trying to merge two rows of data based on a matching ID into a new row, keeping the same ID with a new description column and a total of the two values.

    Existing

    ID Description Total
    ABC Fee A
    $250
    ABC Fee B
    $100
    DEF Fee A
    $25
    DEF Fee B
    $60
    XXA Fee A
    $120
    XXA Fee B
    $80

    Desired Outcome
    ID Description Total
    ABC Fee C
    $350
    DEF Fee C
    $85
    XXA Fee C
    $200

  2. #2
    Conjurer alansidman's Avatar
    Join Date
    Oct 2018
    Location
    Steamboat Springs
    Posts
    202
    Articles
    0
    Excel Version
    2019
    employing Power Query here is the Mcode

    Code:
    let
        Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
        #"Grouped Rows" = Table.Group(Source, {"ID"}, {{"Total1", each List.Sum([Total]), type number}}),
        #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each "Fee C"),
        #"Reordered Columns" = Table.ReorderColumns(#"Added Custom",{"ID", "Custom", "Total1"}),
        #"Renamed Columns" = Table.RenameColumns(#"Reordered Columns",{{"Custom", "Description"}, {"Total1", "Total"}})
    in
        #"Renamed Columns"
    v A B C
    1 ID Description Total
    2 ABC Fee C 350
    3 DEF Fee C 85
    4 XXA Fee C 200

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •