HomeSheets Vs Excel FormulaSUMIFS with XLOOKUP in Excel and Google Sheets

SUMIFS with XLOOKUP in Excel and Google Sheets

Published on

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.

Dynamic Sum Column in SUMIF in Google Sheets

To obtain a dynamic sum column (sum_range argument) in SUMIF, we can utilize the...

Create a Calendar in Excel with a One-Line Dynamic Array Formula

This tutorial explains how to create a calendar in Excel using a one-line formula...

Excel: Month Name to Number & Number to Name

This tutorial showcases the most efficient formulas for converting a month name to a...

Get the First or Last Row/Column in a New Google Sheets Table

If you've recently started using the new Google Sheets TABLE functionality, you may find...

More like this

Counting XLOOKUP Results with COUNTIFS in Excel and Google Sheets

We can use COUNTIF or COUNTIFS alongside an XLOOKUP formula to conditionally count the...

SORT and SORTBY – Excel Vs Google Sheets

While Excel offers the SORT and SORTBY functions for sorting a table, Google Sheets...

SUMPRODUCT Differences: Excel vs. Google Sheets

The core purpose of the SUMPRODUCT function remains consistent across 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.