## [Solved] IF conditions

### [Solved] IF conditions

Hey,
Sorry if this is a basic question, but I've been using calc for a few years and I always been able to find the answers, but I don't really know how to search this.
So, I want to use a IF condition like this:

If the value of the column A is 'x' then i want the correspondent value of B to be added.

Example:

Column A:
A1.Dog
A2.Cat
A3.Dog
A4.Cat
A5.Cat
(...)

Column B:
B1.1
B2.2
B3.1
B4.1
B5.0
(...)

So, IF in A you have "Dog" then i want the sum of the Column B value.
In this case would be B1 + B3 the answer.

Not sure if i explained myself properly, but if you guys can help me, that would be great.
Last edited by Hagar Delest on Thu May 07, 2020 7:10 am, edited 1 time in total.
Reason: tagged solved
OpenOffice 3.1 on Windows 7
DuarteSC

Posts: 4
Joined: Thu May 07, 2020 12:34 am

### Re: IF conditions

I think you want to use the SUMIF function. Something like
Code: Select all   Expand viewCollapse view
`SUMIF(\$A\$1:\$A\$10; A1; \$B\$1:\$B\$10)`

That would sum all of the column B values where the corresponding value in column A is equal to the A1 value.
Windows 10 and Linux Mint, since 2017
FJCC
Moderator

Posts: 7872
Joined: Sat Nov 08, 2008 8:08 pm

### Re: IF conditions

Yet, that's it. Thanks.
Just another question, is it possible to had 2nd condition in order to get the Sum of the values of B?
In this case assuming it had to be a Dog and Grey for example (this value would come from Column C)
OpenOffice 3.1 on Windows 7
DuarteSC

Posts: 4
Joined: Thu May 07, 2020 12:34 am

### Re: IF conditions

There is a SUMIFS function but I prefer the more flexible SUMPRODUCT function.
Code: Select all   Expand viewCollapse view
`=SUMPRODUCT(A1:A8 = "Dog"; B1:B8 = "Grey"; C1:C8)`
Windows 10 and Linux Mint, since 2017
FJCC
Moderator

Posts: 7872
Joined: Sat Nov 08, 2008 8:08 pm

### Re: IF conditions

That's exactly what i needed, thanks, and this code can work for any number of variables right?
OpenOffice 3.1 on Windows 7
DuarteSC

Posts: 4
Joined: Thu May 07, 2020 12:34 am

### Re: IF conditions

SUMPRODUCT has a maximum of 30 arguments. See the HELP - F1 - and you might also find [Tutorial] The SUMPRODUCT function a useful resource.
Cheers
David
Apache OpenOffice 420m2(Build:9821) - Slackware 14.2 - 64 bit
LibreOffice 6.4.6.2 (SlackBuild for 6.4.6 by Eric Hameleers) - Slackware 14.2 - 64 bit
Apache OpenOffice 4.1.4 - Windows 7 Virtual machine

robleyd
Moderator

Posts: 3643
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

### Re: IF conditions

Thanks, you can close the topic.
OpenOffice 3.1 on Windows 7
DuarteSC

Posts: 4
Joined: Thu May 07, 2020 12:34 am