HomeGoogle DocsSpreadsheetHow to Use Sumproduct with Merged Cells In Google Sheets

How to Use Sumproduct with Merged Cells In Google Sheets

Published on

Can I use the Sumproduct function with merged cells in Google Sheets?

Yes! We can do that similar to Sumif in Merged Cells. We can virtually unmerge and fill all of the arrays in use in Sumproduct to get the correct result.

I will walk you through how to do it in Google Sheets.

What Do We Want to Achieve?

We can use Sumproduct to get the sum of products at one go. While doing so, we can include criteria to skip some rows.

In a dataset that contains multiple products such as “ISMC 75”, “ISA 75X75X6”, and “ISMB 200” (some country-specific structural steel items), we can get the sum of the product of any of the above items or all of them.

If we want to stick with any specific items, we must use criteria within the formula.

We will follow that within our example below.

Now let’s see what do we want to achieve here.

In the following example, some of the cells in the columns that contain items, unit, and unit weights are merged.

In cell F2, I have a Sumproduct formula that does the job (return the sum of the product) wonderfully.

Sumproduct with Merged Cells In Google Sheets - Example
screenshot # 1

As I have already mentioned above, some cells are merged in the array in use in the evaluation.

Irrespective of that, the Sumproudct formula in cell F2 returns the product sum as per the criteria in cell E2.

For example, when I select ISMB 200 (a structural steel item) from the drop-down in cell E2, it calculates as follows.

=2*24.2+2.5*24.2

Before revealing the formula in cell F2, you should know what formula you should use when you have no merged cells in the cell range/arrays.

That is very important to know before learning how to use Sumproduct with merged cells in Google Sheets.

Sumproduct with Merged Cells In Google Sheets (Formula and Explanation)

Assume we have unmerged the data and formatted it as below.

screenshot # 2

Then, we can use the below Sumproduct formula to get the sum of the product of the item selected in cell E2.

=sumproduct(
     (A2:A10=E2)*
     B2:B10*
     D2:D10
)

If you analyze this formula, you can understand that we should deal with arrays 1 (cell range A2:A10) and 3 (cell range D2:D10). Please see both of the screenshots above.

We have to unmerge them virtually and fill in data.

I mean, we should replace A2:A10 and D2:D10 with virtual LOOKUP arrays, and here are them.

A2:A10:

lookup(row(A2:A10),if(len(A2:A10),row(A2:A10)),A2:A10)

D2:D10:

lookup(row(A2:A10),if(len(D2:D10),row(A2:A10)),D2:D10)

Here is how to use the Sumproduct function with merged cells in Google Sheets. I have included the above two Lookup virtual arrays in it.

The formula in F2:

=sumproduct(
     (lookup(row(A2:A10),if(len(A2:A10),row(A2:A10)),A2:A10)=E2)*
     B2:B10*
     lookup(row(A2:A10),if(len(D2:D10),row(A2:A10)),D2:D10)
)

To learn the above Lookup formulas, please read my detailed tutorial here – How to Fill Merged Cells Down or to the Right in Google Sheets.

Conclusion

When you want to include more columns, you can change the following cell range references/expressions in the above lookup formula.

Replace all the cell references that are not enclosed within the ROW function with the corresponding cell range.

That’s all about how to use the Sumproduct function with merged cells in Google Sheets.

You can find below a sample sheet and additional resources to deal with merged cells.

Sample_Sheet_29721

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.

Running Total By Month in Excel

This tutorial demonstrates how to calculate the running total by month in a range...

SORT and SORTBY – Excel Vs Google Sheets

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

Get Top N Values Using Excel’s FILTER Function

When using the FILTER function in Excel to extract the top N values, it's...

XLOOKUP in Excel: Working with Visible Rows in a Table

In Excel, the XLOOKUP function isn't inherently designed to exclusively work with visible rows;...

More like this

Interactive Random Task Assigner in Google Sheets

You have multiple tasks and multiple people. Here's a fun way to randomly assign...

Google Sheets Bar and Column Chart with Target Coloring

To color each data point in the column or bar chart according to the...

Analyzing Column A Between Non-Adjacent Values in Column B: Google Sheets

This tutorial addresses a common scenario encountered in Google Sheets: how to sum, average,...

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.