views:

60

answers:

4

Hi,

What would be the equivalent Excel formula of this SQL query

SELECT SUM(a) FROM table WHERE b < 0;

A     B
----  ----
   1     0
   2    -1 
   3     4
   5    -3

>> 7
+2  A: 

Use the SUMIF function.

Marcelo Cantos
That's what I tried, but if I'm not mistaken, the condition is only on one cell or an equality. `SUMIF(B1:B4;<0;A1:A4)` obviously doesn't work, but what to write before the `<`?
gregseth
Put it in quotes: `"<0"`.
Marcelo Cantos
A: 
=SUMIF(B:B,"<0",A:A)
Paul Kearney - pk
A: 

use SUMIFS(a1:a4,b1:b4,"<0") if values in A1:B4 range

bill
A: 

Given:

Row#    A    B

3       1    0
4       2   -1
5       3    4
6       5   -3

=SUMIF(B3:B6; "<0"; A3:A6)
Leniel Macaferi