Compare Two Lists in Excel: XLOOKUP, VSTACK, and Power Query
Comparing two lists in Excel is a common task, especially for accounting and finance professionals who export trial balances each period. The challenge is that the two lists rarely line up perfectly. Accounts with zero balances get suppressed by the system, new accounts appear, and old ones drop off. In this tutorial, we cover three approaches to solve this problem: doing it manually, using dynamic array formulas (VSTACK, UNIQUE, SORT, and XLOOKUP), and using Power Query with a Full Outer join. Each approach produces the same clean, side-by-side comparison of prior and current period balances.
Exercise 1: Manually Aligning Two Lists
Let’s say we have two trial balance exports on the same worksheet. The prior period list lives in rows 9 through 21, and the current period list starts below. Our accounting system suppresses zero-balance accounts, so the two lists do not match row for row.

The manual process goes something like this. We copy the current period balances and paste them next to the prior period list. Then we scroll through row by row, checking account numbers. When we find a mismatch, we insert a row, move data down, and type a zero for the missing balance. We repeat this until everything lines up, then add headers for Prior Period (PP) and Current Period (CP).
It works, but it is tedious and error-prone. Every month we start from scratch and repeat every step. There has to be a better way.

Exercise 2: Using VSTACK, UNIQUE, SORT, and XLOOKUP
Now that we know what we are trying to produce, let’s tackle it with formulas. The goal is a master account list that pulls accounts from BOTH periods, then uses XLOOKUP to fill in the balances. Consider the following worksheet:

The first step is to build a combined, de-duplicated, sorted list of account numbers and names from both tables. We do this by nesting three functions together: VSTACK, UNIQUE, and SORT.
Before diving in, a quick look at the VSTACK function. It vertically stacks multiple arrays into a single array, appending each array below the previous one. The function arguments are:
- array1: the first array or range to include
- array2, …: additional arrays to stack below the first (optional)
We start by using VSTACK to combine the Account and Account name columns from both the prior period table (tb_pp) and the current period table (tb_cp). We could write the following formula into cell G8:
=VSTACK(tb_pp[[Account]:[Account name]],tb_cp[[Account]:[Account name]])

This gives us every account from both lists stacked together. The problem is that accounts appearing in both periods will show up twice. No worries, we can wrap UNIQUE around the whole thing to remove those duplicates.
Here’s a quick refresher on the UNIQUE function. It returns a list of unique values from a range or array, removing any duplicate rows or columns. The function arguments are:
- array: the range or array to evaluate
- by_col: TRUE to compare columns, FALSE (default) to compare rows (optional)
- exactly_once: TRUE to return values that appear exactly once, FALSE (default) to return all unique values (optional)
=UNIQUE(VSTACK(tb_pp[[Account]:[Account name]],tb_cp[[Account]:[Account name]]))

Now we have a clean, de-duplicated list. But the order is a little unpredictable since VSTACK stacks the first table on top and the second below. Let’s sort the result so accounts appear in ascending account number order.
For those new to the SORT function, it returns a sorted version of a range or array. The function arguments are:
- array: the range or array to sort
- sort_index: the column (or row) number to sort by (optional, defaults to 1)
- sort_order: 1 for ascending (default) or -1 for descending (optional)
- by_col: FALSE (default) to sort rows, TRUE to sort columns (optional)
=SORT(UNIQUE(VSTACK(tb_pp[[Account]:[Account name]],tb_cp[[Account]:[Account name]])))

We hit Enter, and bam: a perfectly sorted, de-duplicated master list of all accounts from both periods, including account 6300 Training that only exists in the current period. Now it is time to pull in the balances.
Since we’re about to use XLOOKUP, here’s what it does. It searches a range or array for a match and returns the corresponding item from a second range or array. The function arguments are:
- lookup_value: the value to search for
- lookup_array: the range or array to search in
- return_array: the range or array to return a value from
- if_not_found: value to return when no match is found (optional)
- match_mode: 0 = exact match (default), 1 = exact or next larger, -1 = exact or next smaller, 2 = wildcard (optional)
- search_mode: 1 = search first to last (default), -1 = last to first, 2 = binary ascending, -2 = binary descending (optional)
For the Prior column, we look up the spilled account numbers (G8:G21) against the prior period table and return the Balance. If an account is not found in the prior period (like account 6300), we pass a zero as the if_not_found argument so we get a clean zero instead of an error. We could write the following formula into cell I8:
=XLOOKUP(G8:G21,tb_pp[Account],tb_pp[Balance])

We add the if_not_found argument so that missing accounts return zero rather than an error. Then we write a second XLOOKUP in the Current column, this time pointing to the current period table. We include the same zero fallback for accounts that only appear in the prior period.
=XLOOKUP(G8:G21,tb_cp[Account],tb_cp[Balance],0)

We hit Enter, and bam: both columns are filled. The report is FULLY dynamic. When the source tables are updated with new exports, the master list automatically adjusts to include any new or removed accounts.

Exercise 3: Using Power Query with a Full Outer Join
Now, it is time to make things more interesting. Another excellent approach is Power Query, especially when the source data lives in external files or the dataset is large. The strategy here is to load each table into Power Query as a connection-only query, then merge them using a Full Outer join.
We load the prior period table first. From the Data tab, we select From Table/Range to open the Power Query Editor. Since the data is already clean, we select Close & Load To and choose Connection Only. We repeat this step for the current period table.
With both queries loaded, we go to Get Data, Combine Queries, Merge. We select the prior period query (pq_pp) as the top table and the current period query (pq_cp) as the second. We then click the Account column in each table to define the join key. The critical step is the Join Kind setting.

The default is a Left Outer join, which only keeps accounts from the first table. We need Full Outer (all rows from both), so we change the Join Kind to Full Outer and click OK. This ensures accounts that appear in only one of the two periods are still included.
After expanding the merged column, we can see null values where an account exists in one period but not the other. For example, account 6300 Training shows null in the prior period columns, and account 1050 Prepaids shows null in the current period columns.

Next, we rename the Balance columns to PP (Prior Period) and CP (Current Period) so we can track which is which. Then we need to create unified Account Number and Account Name columns that are not null for any row. We do this with a Conditional Column.
We go to Add Column, Conditional Column. We name it AccNum. The logic is: if the Account column equals null, then use the pq_cp.Account value; otherwise use the Account value. We click OK. We repeat this process for account name, calling the new column AcctName.

With the unified columns in place, we remove the original redundant columns and reorder so AccNum and AcctName appear first. We then sort by AccNum ascending and select the PP and CP columns to replace null values with zero.

We click Close & Load, choose an existing worksheet location, and the final table loads back into Excel. And when we inspect our range, bam, a clean, sorted comparison of both periods with zeros where an account has no balance.

The Power Query approach is particularly powerful because we can simply refresh the query the next time we paste in new exports. No manual row-by-row comparison needed.
Summary
So those are three different ways to compare two lists in Excel and identify what has changed between periods. Exercise 1 showed the manual approach: copy, paste, and painstakingly align rows by hand. Exercise 2 replaced all of that with a handful of dynamic array formulas. We used VSTACK to combine both account lists, UNIQUE to remove duplicates, SORT to order them, and XLOOKUP twice to pull the prior and current balances. Exercise 3 used Power Query with a Full Outer merge to combine the tables, a Conditional Column to unify the account identifiers, and Replace Values to swap nulls for zeros. All three methods produce the same result. The formula approach is great for quick, in-workbook analysis. Power Query shines when the data is large or comes from external sources.
If you have any suggestions, improvements, alternatives, or questions, please share by posting a comment below … thanks!
Sample File
FAQs
Do VSTACK, UNIQUE, and SORT require a specific version of Excel?
Yes. VSTACK requires Excel 365 (it was added in a 2022 update). UNIQUE and SORT require Excel 365 or Excel 2021. If we are on an older version, the Power Query approach in Exercise 3 is available in Excel 2016 and later.
What does a Full Outer join do in Power Query?
A Full Outer join keeps every row from both tables, regardless of whether a match exists in the other table. Rows without a match get null values in the columns from the opposite table. This is exactly what we need when comparing two lists that may have different items.
Why does XLOOKUP return an error instead of a zero for missing accounts?
By default, XLOOKUP returns an error when it cannot find the lookup value. We use the optional if_not_found argument (the fourth argument) and pass a zero. That tells XLOOKUP to return zero instead of an error whenever an account number is not present in that period’s table.
Can we use VLOOKUP instead of XLOOKUP for this?
We can, but VLOOKUP does not have a built-in if_not_found argument. We would need to wrap it in IFERROR to catch the missing-account errors and return a zero. XLOOKUP handles this more cleanly and is the preferred choice in modern Excel.
What happens if a new account is added to one of the source tables?
In Exercise 2, the VSTACK formula references the Excel table columns by structured reference. When a new row is added to either table, the formula automatically picks it up and includes the new account in the master list. No formula edits needed. For the Power Query approach in Exercise 3, we simply click Refresh to pull the new data.
What if the two lists are in separate workbooks?
Power Query handles this scenario best. We can connect to external workbooks using Get Data, From File, From Workbook. Once the connections are set up, we merge the queries exactly as shown in Exercise 3. The formula approach in Exercise 2 can also reference external workbooks, but the file must remain open for the formulas to recalculate.
How do we handle account names that differ between the two periods?
In the formula approach, the VSTACK formula stacks account names from both tables. Because UNIQUE deduplicates by the full row (account number AND account name), a renamed account could appear twice. In Power Query, the Conditional Column logic picks one name over the other, so we may need to add a step to choose which name takes precedence.
Can we add a variance column to show the change between periods?
Absolutely. In Exercise 2, we can add another column with a simple subtraction formula referencing the Current and Prior columns. In Power Query, we can add a Custom Column in the editor with the same subtraction logic, and it will refresh automatically along with the rest of the query.
Why does Power Query use the term ‘null’ instead of blank or zero?
In Power Query, null is the technical representation of a missing or unknown value. It is the equivalent of an empty cell in Excel. We use Replace Values to swap null for zero before loading the data back to the worksheet, which makes the output easier to work with in formulas and PivotTables.
What is the advantage of using structured table references like tb_pp[Account] in the formulas?
Structured references automatically adjust when rows are added to or removed from the table. We do not need to update the formula ranges manually each period. This makes the formula approach in Exercise 2 much more robust and easy to maintain over time.
Which approach should we use: formulas or Power Query?
It depends on the situation. If the data is already in the same workbook and the lists are relatively small, the VSTACK and XLOOKUP formula approach is fast and elegant. If the data lives in external files, databases, or is very large, Power Query is the better tool. It handles data transformation steps more transparently and refreshes with a single click.
Excel is not what it used to be.
You need the Excel Proficiency Roadmap now. Includes 6 steps for a successful journey, 3 things to avoid, and weekly Excel tips.
Want to learn Excel?
Our training programs start at $29 and will help you learn Excel quickly.