SUMIFS with XLOOKUP in Excel and Google Sheets

SUMIFS and SUMIF are infamous for producing an “argument must be a range” error when using an expression as the sum range. However, when XLOOKUP is employed as the sum range in SUMIFS, this error does not arise.

Therefore, we can use SUMIFS with XLOOKUP to conditionally sum an XLOOKUP result in Excel and Google Sheets.

In this combo, XLOOKUP looks up and returns an array using one of its advanced lookup capabilities, such as searching from last value to first value, first value to last value, approximate match, exact match, wildcard match, etc. SUMIFS then sums the values based on conditions.

This post contains a common example applicable to both Excel and Google Sheets.

An Example of SUMIFS with XLOOKUP in Excel and Google Sheets

The sample data consists of employee names in column A and their monthly salaries from January to December in columns B to M.

We will utilize XLOOKUP to search for a name in column A and retrieve their 12-month salary, then sum it across specific months using SUMIFS.

Sample Data for testing XLOOKUP and SUMIFS combo

In the table above, I want to find the total salary of “Rachel Powell” in October, November, and December (4th quarter) of 2023.

Here are the step-by-step instructions:

XLOOKUP Part:

Syntax: XLOOKUP(search_key, lookup_range, result_range, [missing_value], [match_mode], [search_mode])

This is the XLOOKUP syntax in Google Sheets. You can follow the same in Excel, although the parameter names slightly vary.

In Excel, search_key will be lookup_value, lookup_range will be lookup_array, result_range will be return_array, and missing_value will be if_not_found. They refer to the same. The last two parameter names, i.e., match_mode and search_mode, are the same in XLOOKUP in Excel and Google Sheets.

Enter the employee name (search_key) in cell O2, which is “Rachel Powell”.

Enter =XLOOKUP(O2, A2:A4, B2:M4) in cell P2 to look up the name in cell O2 in A2:A4 and return the salaries from B2:M4.

XLOOKUP to retrieve salaries of employees

If the formula fails to expand, the formula may return a #SPILL error in Excel and a #REF error in Google Sheets. In that case, ensure that P2:AA2 doesn’t contain any values.

How to SUMIFS this XLOOKUP result? We can see that below.

SUMIFS Part:

Syntax: SUMIFS(sum_range, criteria_range1, criterion1, [criteria_range2, …], [criterion2, …])

The SUMIFS syntax is the same in both Excel and Google Sheets. Now let’s dive straight into the SUMIFS and XLOOKUP combo formula.

=SUMIFS(XLOOKUP(O2, A2:A4, B2:M4), B1:M1, ">="&DATE(2023, 10, 1), B1:M1, "<="&DATE(2023, 12, 1))
SUMIFS with XLOOKUP to sum salaries based on specified conditions

Where:

  • sum_range: XLOOKUP(O2, A2:A4, B2:M4)
  • criteria_range1: B1:M1
  • criterion1: ">="&DATE(2023, 10, 1) – the date is entered according to the syntax DATE(year, month, day)
  • criteria_range2: B1:M1
  • criterion2: "<="&DATE(2023, 12, 1) – the date is entered according to the syntax DATE(year, month, day)

The SUMIFS function sums the XLOOKUP result matching the dates in the header row of the table.

This is an example of SUMIFS with XLOOKUP in Excel and Google Sheets.

What if I Have Month Names Instead of Month Start Dates?

As you can see in the sample data, B1:M1 contains the month start dates. I mean 1/1/23 represents January, and 1/12/23 represents December. So we have used dates as criteria in SUMIFS.

You may have a reason to use month texts such as January, February, … December instead in B1:M1.

In that case, you can convert those month texts to month numbers within the SUMIFS and XLOOKUP combo formula in Google Sheets and outside the formula in Excel. This is because of the dynamic array difference in both applications.

In Google Sheets:

Replace B1:M1 (appears twice) in the SUMIFS and XLOOKUP combo formula with DATE(2023, MONTH(B1:M1&1), 1). Then wrap the formula with the ARRAYFORMULA function as follows:

=ArrayFormula(SUMIFS(XLOOKUP(O2, A2:A4, B2:M4), DATE(2023, MONTH(B1:M1&1), 1), ">="&DATE(2023, 10, 1), DATE(2023, MONTH(B1:M1&1), 1), "<="&DATE(2023, 12, 1)))

In Excel, enter =DATE(2023, MONTH(B1:M1&1), 1) in cell P1, provided P1:AA1 are blank. Then replace B1:M1 (twice) in the formula with P1:AA1.

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

How to Create a Case-Sensitive Pivot Table in Google Sheets

To create a case-sensitive pivot table in Google Sheets, we will use a helper...

Marking Case-Sensitive Unique Values in Excel

Marking case-sensitive unique values provides several benefits compared to merely extracting them in an...

Highlight Upcoming Birthdays in Google Sheets

When highlighting upcoming birthdays in Google Sheets, one important aspect is ignoring the year...

Compare Two Tables for Differences in Excel

To compare two tables with similar data for differences, you can use the XLOOKUP...

More like this

Lookup Previous Values Dynamically in Excel and Google Sheets

Sometimes, you may want to look up the previous values relative to the current...

Sort Data but Keep Blank Rows in Excel and Google Sheets

Using a dynamic array formula or the FILTER command, we can sort data and...

Lookup Values Under Categories in Excel and Google Sheets

We can use a combination of XLOOKUP and VLOOKUP in both Excel and Google...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.