Jump to content

To sum satisfying two conditions in excel

Kicchagee's Photo
Posted Nov 24 2009 04:54 AM
5090 Views

How to get the sum from a data range satisfying two conditions in excel. Normally I use sumif to get the total from a data range satisfying a condition but I want to get the total from a data range satisfying 2 or more than 2 conditions. Thank you and expecting your answer. I have given the sample data for your reference.

Chq.#	Date	         SSN	NAME		           AMOUNT

19410	31-Mar-09	1223	DARRELL Ravi		 30,000.00 
19411	1-Apr-00	1122	BILL HURY		 15,000.00 
19412	2-Apr-09	13414	STEVE MANDROF		 18,519.21 
19412	4-Feb-09	1222	DAVID SPONGE		 13,401.25 
19410	31-Mar-09	1087	JOA FERNANX		 1,500.00 
19415	31-Mar-09	39399	SCOTT RANGS		 68,440.50 
19415	31-Mar-09	808	TODD SKEELTON		 5,921.60 





Data satisfying the date = "03/31/09" = sumif(data range,"03/31/09",amountrange) 105,862.10
Data satisfying the date = "03/31/09" and Chq.#

Tags:
1 Subscribe


1 Reply

+ 3
  odewahn1's Photo
Posted Nov 24 2009 09:05 AM

This is a bit of a hack solution, but it will always work:

  • Create a cell for each condition you want to test. It should return a "1" if the condition is met, and "0" otherwise.
  • Create a new cell (lets call it flag). This cell should return either 1 or 0, depending on the type of overall conditional you want. For example, if you want to include the value if any one of a number of conditions is met (an "OR" test), then the flag should be set to 1 if the sum of the individual conditionals is greater than zero. If you want to add the value only when all the conditions are met (an "AND" test), then you'd return 1 if the sum of the individual conditionals equals the number of conditions you're testing.
  • Finally, create a new cell that multiplies the value you want to test by the flag cell. This cell will equal the value if the condition is met (i.e., the flag cell = 1); otherwise, it will be equal to 0.


An example will make this clearer. Here is your original data, with a few extra columns that I've added to do some conditional testing:

Attached Image


  • Column F is the logical test for the first condition. Its formula is "=IF(B1=DATEVALUE("03/31/09"),1,0)"
  • Column G is the second conditional. Its formula is "=IF(A1>19411,1,0)"
  • Column H is the "flag" conditional. Its formula is "=IF(SUM(F1:G1) > 0,1,0)"
  • Column I is the conditional value. It's equal to column H*E.

The sum of Column I is the conditional total you're interested in. Note that you could add as many conditions as you want to make this more complex.

To do an "AND" test, set column H (the flag) to "=IF(SUM(F1:G1) = 2,1,0)." Now column H no equals 1 only when all the conditions are met.

Attached Image

If you don't like the look of extra columns (or you're just a glutton for punishment), you could put everything in one huge "If" statement. But, that can be very hard to debug, so I prefer to to build it up step by step, (Alternatively, you could just hide the extra columns.)

Hope this helps!