Combine every two rows in a spreadsheet into one based on criteria

brenda peluso 0 Reputation points
2026-11-02T22:02:44.0533333+00:00

I have an export from one accounting program that uses double entry accounting and I need to convert it to single entry to import to my new program.

Currently each transaction has a unique identifier (Transaction ID) but it takes up two rows in the export.

Current Columns are:

  • Transaction ID# - same for pairs of transactions
  • Transaction Date - same for pairs of transactions
  • Account Group - asset, liability, expense, Income
  • Account Type - Sub-categories of Account Groups (credit card, bank account, long-term asset...)
  • Account Name - A mix of accounts (assets/Liabilities) and Categories (expense, Income)
  • Transaction Description - same for pairs of transactions
  • Amount (one column)
  • Vendor - same for pairs of transactions
  • Customer - same for pairs of transactions

In the resulting spreadsheet - I want to combine rows with the same transaction ID (2 rows) into one row with the following column configuration:

  • Transaction ID#
  • Transaction Date
  • Account Group - asset, liability
  • Category Group - expense, Income
  • Account Type - Sub-categories asset, Liability
  • Category Type - Sub-categories expenses and Income
  • Account Name - (assets/Liabilities)
  • Category Name - (expense, Income)
  • Transaction Description - same for pairs of transactions
  • Amount (one column) - the amount associated with the expense/ income row
  • Vendor
  • Customer

Any ideas? Thanks.

Microsoft 365 and Office | Excel | Other | MacOS
0 comments No comments

2 answers

Sort by: Most helpful
  1. Marcin Policht 112.4K Reputation points MVP Volunteer Moderator
    2026-11-02T22:24:08.9866667+00:00

    Use an Excel Table named SourceData. Create a second table with one row per unique Transaction ID. The formulas below assume exactly two rows per transaction, with one Asset/Liability row and one Expense/Income row.

    Account Group

    =LET(ID,[@[Transaction ID#]],XLOOKUP(1,(SourceData[Transaction ID#]=ID)*((SourceData[Account Group]="Asset")+(SourceData[Account Group]="Liability")),SourceData[Account Group]))
    

    Category Group

    =LET(ID,[@[Transaction ID#]],XLOOKUP(1,(SourceData[Transaction ID#]=ID)*((SourceData[Account Group]="Expense")+(SourceData[Account Group]="Income")),SourceData[Account Group]))
    

    Account Type

    =LET(ID,[@[Transaction ID#]],XLOOKUP(1,(SourceData[Transaction ID#]=ID)*((SourceData[Account Group]="Asset")+(SourceData[Account Group]="Liability")),SourceData[Account Type]))
    

    Category Type

    =LET(ID,[@[Transaction ID#]],XLOOKUP(1,(SourceData[Transaction ID#]=ID)*((SourceData[Account Group]="Expense")+(SourceData[Account Group]="Income")),SourceData[Account Type]))
    

    Account Name

    =LET(ID,[@[Transaction ID#]],XLOOKUP(1,(SourceData[Transaction ID#]=ID)*((SourceData[Account Group]="Asset")+(SourceData[Account Group]="Liability")),SourceData[Account Name]))
    

    Category Name

    =LET(ID,[@[Transaction ID#]],XLOOKUP(1,(SourceData[Transaction ID#]=ID)*((SourceData[Account Group]="Expense")+(SourceData[Account Group]="Income")),SourceData[Account Name]))
    

    Amount

    =LET(ID,[@[Transaction ID#]],XLOOKUP(1,(SourceData[Transaction ID#]=ID)*((SourceData[Account Group]="Expense")+(SourceData[Account Group]="Income")),SourceData[Amount]))
    

    Transaction Date, Transaction Description, Vendor, Customer

    =XLOOKUP([@[Transaction ID#]],SourceData[Transaction ID#],SourceData[Transaction Date])
    

    Replace Transaction Date with the respective column name for each formula.


    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    Was this answer helpful?

    0 comments No comments

  2. AI answer

    2026-11-02T22:03:48.19+00:00

    Use Power Query to group each pair by Transaction ID, select the asset/liability row and expense/income row, and return one record containing fields from both rows.

    Create the query in Excel for Mac

    Power Query Editor is generally available to Microsoft 365 subscribers using Excel for Mac version 16.69 or later.^1^

    1. Select the exported data and format it as an Excel table.
    2. On Table Design, change the table name to Transactions.
    3. Select Data > Get Data (Power Query) > Launch Power Query Editor.
    4. Create a query from the Transactions table.
    5. Open Advanced Editor and replace the query with the code below.
    6. Select Done, then Home > Close & Load.

    Power Query’s Table.Group operation creates one result for each unique grouping key—in this case, each Transaction ID.^2^

    let
        Source = Excel.CurrentWorkbook(){[Name="Transactions"]}[Content],
        Grouped = Table.Group(Source, {"Transaction ID#"}, {
            {"Result", (t) =>
                let
                    AccountRows = Table.SelectRows(t, each
                        List.Contains({"asset", "liability"},
                            Text.Lower(Text.From([Account Group])))),
                    CategoryRows = Table.SelectRows(t, each
                        List.Contains({"expense", "income"},
                            Text.Lower(Text.From([Account Group])))),
                    Common = t{0},
                    Account = try AccountRows{0} otherwise null,
                    Category = try CategoryRows{0} otherwise null
                in [
                    TransactionDate = Common[Transaction Date],
                    AccountGroup = try Account[Account Group] otherwise null,
                    CategoryGroup = try Category[Account Group] otherwise null,
                    AccountType = try Account[Account Type] otherwise null,
                    CategoryType = try Category[Account Type] otherwise null,
                    AccountName = try Account[Account Name] otherwise null,
                    CategoryName = try Category[Account Name] otherwise null,
                    TransactionDescription = Common[Transaction Description],
                    Amount = try Category[Amount] otherwise null,
                    Vendor = Common[Vendor],
                    Customer = Common[Customer]
                ], type record}
        }),
        Expanded = Table.ExpandRecordColumn(Grouped, "Result", {
            "TransactionDate", "AccountGroup", "CategoryGroup",
            "AccountType", "CategoryType", "AccountName", "CategoryName",
            "TransactionDescription", "Amount", "Vendor", "Customer"
        }, {
            "Transaction Date", "Account Group", "Category Group",
            "Account Type", "Category Type", "Account Name", "Category Name",
            "Transaction Description", "Amount", "Vendor", "Customer"
        })
    in
        Expanded
    

    The result has one row per Transaction ID, with:

    • Account fields taken from the asset or liability row.
    • Category fields taken from the expense or income row.
    • Amount taken from the expense/income row.
    • Date, description, vendor, and customer taken from the first row in the pair.

    The query does not depend on the two source rows being adjacent. Power Query groups all rows sharing the same key, and its All rows behavior can retain the complete set of records inside each group.^2^

    Adjustments and validation

    • The column names in the code must exactly match the headers in the export. For example, change "Transaction ID#" if the actual header is "Transaction ID".
    • Comparisons are case-insensitive, but the group values must otherwise be asset, liability, expense, or income.
    • A missing account/category side produces blank fields rather than stopping the query.
    • If one Transaction ID can contain more than one account row or category row, the query currently uses the first matching row. An aggregation rule—such as summing multiple category amounts—would need to be defined. Power Query supports aggregate operations such as Sum, Min, Max, and Count during grouping.^2^
    • After replacing the accounting export, select Data > Refresh All to regenerate the import table.^1^

    If Launch Power Query Editor is unavailable, check the Excel version under Excel > About Microsoft Excel. Power Query support differs across Mac versions and editions.^3^


    References

    1. Import and shape data in Excel for Mac (Power Query)
    2. Grouping or summarizing rows
    3. About Power Query in Excel
    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.