[Solved] IF conditions

Discuss the spreadsheet application

[Solved] IF conditions

Postby DuarteSC » Thu May 07, 2020 12:44 am

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

Postby FJCC » Thu May 07, 2020 1:20 am

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
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7748
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: IF conditions

Postby DuarteSC » Thu May 07, 2020 1:32 am

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

Postby FJCC » Thu May 07, 2020 4:50 am

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
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7748
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: IF conditions

Postby DuarteSC » Thu May 07, 2020 5:23 am

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

Postby robleyd » Thu May 07, 2020 5:40 am

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.0.7.3 - Slackware 14.2 - 64 bit
Apache OpenOffice 4.1.4 - Windows 7 Virtual machine
User avatar
robleyd
Moderator
 
Posts: 3458
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: IF conditions

Postby DuarteSC » Thu May 07, 2020 6:13 am

Thanks, you can close the topic.
OpenOffice 3.1 on Windows 7
DuarteSC
 
Posts: 4
Joined: Thu May 07, 2020 12:34 am


Return to Calc

Who is online

Users browsing this forum: Bidouille, Google [Bot] and 23 guests