Essential Excel Formulas: VLOOKUP, XLOOKUP, SUMIFS
In this article
Mastering Excel formulas allows you to move beyond simple data entry and perform dynamic analysis, automate repetitive tasks, and create robust reports. The most useful formulas—VLOOKUP, XLOOKUP, and SUMIFS—enable you to connect data from different sheets, sum values based on multiple conditions, and update results automatically as your data changes. This guide focuses on these three indispensable tools, which are core to most professional data work.
What You'll Need
- A computer with Microsoft Excel installed (2016 or later is recommended for XLOOKUP).
- A spreadsheet containing at least two data sets. For this guide, we will use a small example of a sales dataset with a separate lookup table for product details.
- A basic understanding of spreadsheet columns (A, B, C) and rows (1, 2, 3).
Step-by-Step
Below are the specific steps to set up a sample dataset and apply the three formulas. The logic applies to any real-world dataset of similar size and structure.
1. Prepare Your Data
- Open a new Excel workbook.
- In cell A1, type “Product ID.” In cell B1, type “Product Name.” In cell C1, type “Sales Amount.” This will be your main sales data sheet.
- Enter sample data in the rows below. For example, in row 2, type “101” in A2, “Widget A” in B2, and “500” in C2. Repeat for a few more rows with different IDs and amounts.
- Go to a new sheet (Sheet2) by clicking the “+” button at the bottom of the window.
- In cell A1 on Sheet2, type “Product ID.” In cell B1, type “Category.” This will be your lookup table.
- Enter lookup data. For example, in row 2, type “101” in A2 and “Electronics” in B2. Add a few more rows with different IDs and their respective categories.
2. Use VLOOKUP to Find a Value
VLOOKUP searches for a value in the first column of a table and returns a value in the same row from a specified column. It is widely used to pull in missing information, such as a product category based on its ID.
- Go back to your main data sheet (Sheet1).
- Click on cell D2, which is empty and to the right of your sales data.
- Type the following formula into the formula bar:
=VLOOKUP(A2, Sheet2!A:B, 2, FALSE)- A2 is the value you want to find, which is the Product ID in your current row.
- Sheet2!A:B is the range to search. This tells Excel to look in the first column of Sheet2, from column A to column B.
- 2 is the column index number. Since the “Category” is in the second column of your lookup range (Sheet2!A:B), you use 2.
- FALSE is the range lookup argument. It must be set to FALSE to find an exact match. Using TRUE for approximate match can return incorrect data if the IDs are not sorted.
- Press Enter. The formula should return “Electronics” in cell D2.
- Double-click the fill handle (the small square at the bottom-right corner of cell D2) to apply the formula to the rest of your rows.
3. Use XLOOKUP to Find a Value (The Modern Alternative)
XLOOKUP is a newer function that replaces VLOOKUP and HLOOKUP. It is more flexible and easier to use because you don’t need to specify the column index number. It also has a built-in error handling feature that prevents the common “#N/A” error.
- Click on cell E2 on your main data sheet.
- Type the following formula into the formula bar:
=XLOOKUP(A2, Sheet2!A:A, Sheet2!B:B)- A2 is the value you want to find.
- Sheet2!A:A is the array to search for the value.
- Sheet2!B:B is the array to return the corresponding value from.
- Press Enter. The formula should return “Electronics” in cell E2.
- Double-click the fill handle to apply the formula to the rest of your rows.
4. Use SUMIFS to Sum Values Based on Multiple Conditions
SUMIFS adds numbers in a range that meet multiple criteria. For example, you might want to calculate the total sales for a specific product category in a specific year. This is impossible with a standard SUM function and requires SUMIFS.
- Ensure your main data sheet (Sheet1) has a “Date” column. Let’s assume the date is in column D and the sales amount is in column C.
- Click on a cell, such as F1, and type “Total Sales for Electronics.”
- Click on cell F2 and type the following formula:
=SUMIFS(C:C, B:B, "Electronics", D:D, ">=01/01/2023")- C:C is the sum range, the column containing the sales amounts.
- B:B is the first criteria range, the column containing the product names.
- "Electronics" is the first criterion, the specific name you want to match.
- D:D is the second criteria range, the column containing the dates.
- ">=01/01/2023" is the second criterion, the date condition you want to apply.
- Press Enter. Excel will calculate the sum of all sales for “Electronics” that occurred on or after January 1, 2023.
Common Mistakes
Avoid these frequent errors to ensure your formulas work correctly.
1. Incorrect Column Index Number in VLOOKUP
The most common mistake is using the wrong column number. Remember that the column containing the value you want to find is always number 1. If you want to return a value from the second column, you must use 2. If you use 1, you will just get the Product ID back.
2. Forgetting to Lock the Lookup Range with $ Signs
When dragging a VLOOKUP or XLOOKUP formula down a column, you must lock the lookup range. Otherwise, Excel will try to search in the wrong columns on the next row. To lock the range Sheet2!A:B, change it to Sheet2!$A:$B. The dollar signs tell Excel to keep the A and B column references constant.
3. Not Using Exact Match (FALSE) in VLOOKUP
If you are looking up a unique identifier like a Product ID, always use FALSE for the range lookup argument. If you use TRUE, Excel will search for the closest match. If you have an ID of 100 and the closest match is 90, Excel will return data for 90, which is incorrect.
Tips
1. Use Named Ranges for Clarity
Instead of referencing a range like Sheet2!A:B, you can give it a name. Select the range in Sheet2, go to the “Formulas” tab, and click “Define Name.” Name it “ProductTable.” Then, in your formula, you can simply use ProductTable. This makes your formulas much easier to read and understand.
2. Check for Extra Spaces
A common cause of VLOOKUP or XLOOKUP errors is hidden spaces. If your lookup value “Electronics” has a space at the end, it will not match a perfectly clean “Electronics” in your data table. Use the TRIM() function to remove spaces from text, or use the “Find and Replace” tool to replace all spaces with an empty string.
3. Use XLOOKUP for Its Error Handling
When a VLOOKUP cannot find a value, it returns the error code #N/A. This can be visually distracting in a large spreadsheet. XLOOKUP has a built-in if_not_found argument. You can specify a text message like “Not Found” to be returned instead of an error code, making your reports look much more professional.
Troubleshooting
If your formula is not returning the expected result, follow these steps to diagnose the issue.
1. The Formula Returns #N/A or #VALUE!
This usually means there is a mismatch in the data types. Check that the value you are looking up in the formula (e.g., “Electronics”) exactly matches the data in the table, including capitalization and spaces. If you are looking up a number, ensure the lookup table column is formatted as a number and not as text.
2. The Formula Returns an Incorrect Value
If you are using VLOOKUP with FALSE and still getting the wrong answer, it is likely because the lookup range is not correct. Double-check that you have included the entire column or range you intend to search. Also, ensure that your data is sorted if you are using TRUE for the range lookup argument.
3. The Formula Returns a #REF! Error
A #REF! error indicates that a cell reference in your formula is no longer valid. This can happen if you have deleted a column or row that was part of your formula’s range. Review your formula to ensure all references point to existing cells.
Frequently Asked Questions
Can I use VLOOKUP on a table that has been filtered?
No, VLOOKUP and XLOOKUP operate on the raw data in the range you specify. If the table is filtered, the formula will still look at all cells in the specified range, not just the visible ones. You must unfilter your data for the formula to work correctly.
What is the difference between SUM and SUMIFS?
The standard SUM function adds all numbers in a range without any conditions. SUMIFS, on the other hand, allows you to specify one or more criteria that the numbers must meet to be included in the sum.
Why is XLOOKUP not available in my version of Excel?
XLOOKUP was introduced in Excel 2021 and is not available in older versions of Excel for Windows or Mac. If you have an older version, you will need to use VLOOKUP or INDEX/MATCH as an alternative.
Can I use wildcards in XLOOKUP?
Yes, XLOOKUP supports wildcard characters. The asterisk (*) represents any number of characters, and the question mark (?) represents a single character. You can use these to perform partial matches, such as finding all products that start with the letter “A”.
Does the order of criteria matter in SUMIFS?
No, the order of the criteria ranges and criteria does not matter in SUMIFS. As long as the first range corresponds to the first criterion, and so on, the formula will calculate correctly.
How do I update a formula when I insert a new column?
If you insert a new column to the left of a VLOOKUP formula, the column index number may need to be adjusted. XLOOKUP is generally more robust in this regard because it references entire columns (e.g., Sheet2!B:B) rather than specific column numbers.