Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SUMIFS function in Google Spreadsheet

Tags:

I'm trying to have a similar function to SUMIFS (like SUMIF but with more than a single criterion) in a Google Spreadsheet. MS-Excel has this function built-in (http://office.microsoft.com/en-us/excel-help/sumifs-function-HA010342933.aspx?CTT=1).

I've tried to use ArrayFormula (http://support.google.com/docs/bin/answer.py?hl=en&answer=71291), similar to the SUMIF:

=ARRAYFORMULA(SUM(IF(A1:A10>5, A1:A10, 0)))

By Adding AND:

=ARRAYFORMULA(SUM(IF(AND(A1:A10>5,B1:B10=1), C1:C10, 0)))

But the AND function didn't pick up the ArrayFormula instruction and returned FALSE all the times.

The only solution I could find was to use QUERY which seems a bit slow and complex:

=SUM(QUERY(A1:C10,"Select C where A>5 AND B=1"))

My Target is to fill up a table (similar to a Pivot Table) with many values to calculate:

=SUM(QUERY(DataRange,Concatenate( "Select C where A=",$A2," AND B=",B$1)))

Did anyone manage to do it in a simpler and faster way?

like image 577
Guy Avatar asked Feb 03 '12 12:02

Guy


People also ask

How Sumif function works in Google Sheets?

The SUMIF function is a premade function in Google Sheets, which calculates the sum of values in a range based on a true or false condition. The condition is referred to as criterion , which can check things like: If a number is greater than another number > If a number is smaller than another number <

How do I Sumifs multiple criteria in one column in Google Sheets?

When you want to use multiple criteria in the same column in SUMIF, probably you are doing like this. You may first use a single criterion in one SUMIF formula and then another SUMIF formula with another criterion. Finally, you can add both the SUMIF formulas.

What is Sumifs function?

The SUMIFS function, one of the math and trig functions, adds all of its arguments that meet multiple criteria. For example, you would use SUMIFS to sum the number of retailers in the country who (1) reside in a single zip code and (2) whose profits exceed a specific dollar value.


1 Answers

The simplest way to easily make SumIFS-like functions in my opinion is to combine the FILTER and SUM function.

SUM(FILTER(sourceArray, arrayCondition_1, arrayCondition_2, ..., arrayCondition_30))

For example:

SUM(FILTER(A1:A10;A1:A10>5;B1:B10=1)

Explanation: the FILTER() filters the rows in A1:A10 where A1:A10 > 5 and B1:B10 = 1. Then SUM() sums the values of those cells.

This approach is very flexible and easily allows for making COUNTIFS() functions for example as well (just use COUNT() instead of SUM()).

like image 166
Javaaaa Avatar answered Sep 27 '22 22:09

Javaaaa