How to Search for a value and sum a related one?

Discuss the spreadsheet application

How to Search for a value and sum a related one?

Postby s.tsiolas » Wed Nov 04, 2009 12:24 am

In column A I have drop down lists (names of different products). In Column B there is an input of how many kg is going to be used. In column A one specific product may be appeared more than one times and the same is happening in other columns. I.E.

A1 = productA , B1= 100
A10 = productA, B10=30
C11 = productA, D11=70
E100= productA, F100=200

What I need is a formula that will search the whole page for product A and then sum the cell with its quantity. In the above example the result I am searching for is 400.

Could somebody please help me with that?

Thanks a lot!
OpenOffice 3.1 on Windows Vista
s.tsiolas
 
Posts: 9
Joined: Mon Oct 19, 2009 1:48 pm

Re: How to Search for a value and sum a related one?

Postby ken johnson » Wed Nov 04, 2009 1:09 am

This array formula seems to work...
=SUM(IF(A1:I14="Product A";1;0)*OFFSET(A1:I14;0;1))

just change the range searched from A1:I14 to suit your needs.
Array formulas have to be entered using the Ctrl+Shift+Enter key combination and in Calc you cannot use the fill handle to copy it to neighbouring cells, the first cell with the formula has to be copied then it can be pasted into other cells using the Paste button or Ctrl+V

Ken Johnson
OOo 3.1.1 on Ms Windows XP + none
ken johnson
 
Posts: 73
Joined: Sun May 31, 2009 1:35 am
Location: Sydney, Australia

Re: How to Search for a value and sum a related one?

Postby acknak » Wed Nov 04, 2009 1:11 am

Here's one approach:
=SUM(
SUMPRODUCT(A1:A100="productA";B1:B100);
SUMPRODUCT(C1:C100="productA";D1:D100);
SUMPRODUCT(E1:E100="productA";F1:F100))

You may have to enter it all on one line to get Calc to accept it.

Since the information is spread over several columns, I can't think of a way to do the sum all at once.
OOo 3 • Linux • Fedora 11
User avatar
acknak
Moderator
 
Posts: 7898
Joined: Mon Oct 08, 2007 1:25 am
Location: 39.916,-75.08

Re: How to Search for a value and sum a related one?

Postby s.tsiolas » Wed Nov 04, 2009 11:19 pm

I have tried both options but it seams that they cannot work. Can you please upload a small sample just to see it in action?

Thanks a lot!
OpenOffice 3.1 on Windows Vista
s.tsiolas
 
Posts: 9
Joined: Mon Oct 19, 2009 1:48 pm

Re: How to Search for a value and sum a related one?

Postby ken johnson » Thu Nov 05, 2009 2:46 am

Attached doc shows both approaches in action.
Ken Johnson
Sum Product Weights.ods
(17.42 KiB) Downloaded 5 times
OOo 3.1.1 on Ms Windows XP + none
ken johnson
 
Posts: 73
Joined: Sun May 31, 2009 1:35 am
Location: Sydney, Australia


Return to Calc

Who is online

Users browsing this forum: Yahoo [Bot] and 8 guests