PC Review


Reply
Thread Tools Rate Thread

Adding items in a column if value in a second column is X.

 
 
paulkaye
Guest
Posts: n/a
 
      14th Jan 2008
Hi,
This one is getting the better of me, even though I know I should be
able to figure it out myself!:

I have two columns of data: B and C.
I have one column of ID#: A

I would like to subtract C from B in all rows where ID# is X and
display the sum of these values in a single cell. I would then like to
do the same for all rows where ID# is Y.

Please help!

Many thanks for your time,

Paul
 
Reply With Quote
 
 
 
 
Pete_UK
Guest
Posts: n/a
 
      14th Jan 2008
Try these:

=SUMPRODUCT((A1:A100="X")*(B1:B100-C1:C100))

=SUMPRODUCT((A1:A100="Y")*(B1:B100-C1:C100))

Adjust column ranges to suit, but you can't have a complete column
(unless you have XL2007).

Hope this helps.

Pete



On Jan 14, 6:47*am, paulkaye <paulmjk...@gmail.com> wrote:
> Hi,
> This one is getting the better of me, even though I know I should be
> able to figure it out myself!:
>
> I have two columns of data: B and C.
> I have one column of ID#: A
>
> I would like to subtract C from B in all rows where ID# is X and
> display the sum of these values in a single cell. I would then like to
> do the same for all rows where ID# is Y.
>
> Please help!
>
> Many thanks for your time,
>
> Paul


 
Reply With Quote
 
paulkaye
Guest
Posts: n/a
 
      14th Jan 2008
Hi,

I got a #VALUE! error.

I don't quite understand the formula - it looks like it does something
like:

A1*(B1-C1)
+A2*(B2-C2)
+A3*(B3-C3)
....

Could you explain? I was expecting to do something with IF statements!

Many thanks again for your time,

Paul

On Jan 14, 11:37 am, Pete_UK <pashu...@auditel.net> wrote:
> Try these:
>
> =SUMPRODUCT((A1:A100="X")*(B1:B100-C1:C100))
>
> =SUMPRODUCT((A1:A100="Y")*(B1:B100-C1:C100))
>
> Adjust column ranges to suit, but you can't have a complete column
> (unless you have XL2007).
>
> Hope this helps.
>
> Pete
>
> On Jan 14, 6:47 am, paulkaye <paulmjk...@gmail.com> wrote:
>
> > Hi,
> > This one is getting the better of me, even though I know I should be
> > able to figure it out myself!:

>
> > I have two columns of data: B and C.
> > I have one column of ID#: A

>
> > I would like to subtract C from B in all rows where ID# is X and
> > display the sum of these values in a single cell. I would then like to
> > do the same for all rows where ID# is Y.

>
> > Please help!

>
> > Many thanks for your time,

>
> > Paul


 
Reply With Quote
 
Pete_UK
Guest
Posts: n/a
 
      14th Jan 2008
The first part of the formula (A1:A100="X") is in fact a conditional
statement which will check in turn if A1="X", A2="X", A3="X" etc and
return TRUE or FALSE as appropriate, which will be interpreted as 1 or
0 respectively. Hence:

(1 or 0)*(B1-C1)
+(1 or 0)*(B2-C2)
+(1 or 0)*(B3-C3)

will give (Bx - Cx) only where Ax = "X", which is what you want.

Check that you have proper numbers in columns B and C, and not text
values. An alternative that you might like to try is:

=SUMPRODUCT(--(A1:A100="X"),(B1:B100-C1:C100))

Hope this helps.

Pete


On Jan 14, 10:08*am, paulkaye <paulmjk...@gmail.com> wrote:
> Hi,
>
> I got a #VALUE! error.
>
> I don't quite understand the formula - it looks like it does something
> like:
>
> * A1*(B1-C1)
> +A2*(B2-C2)
> +A3*(B3-C3)
> ...
>
> Could you explain? I was expecting to do something with IF statements!
>
> Many thanks again for your time,
>
> Paul
>
> On Jan 14, 11:37 am, Pete_UK <pashu...@auditel.net> wrote:
>
>
>
> > Try these:

>
> > =SUMPRODUCT((A1:A100="X")*(B1:B100-C1:C100))

>
> > =SUMPRODUCT((A1:A100="Y")*(B1:B100-C1:C100))

>
> > Adjust column ranges to suit, but you can't have a complete column
> > (unless you have XL2007).

>
> > Hope this helps.

>
> > Pete

>
> > On Jan 14, 6:47 am, paulkaye <paulmjk...@gmail.com> wrote:

>
> > > Hi,
> > > This one is getting the better of me, even though I know I should be
> > > able to figure it out myself!:

>
> > > I have two columns of data: B and C.
> > > I have one column of ID#: A

>
> > > I would like to subtract C from B in all rows where ID# is X and
> > > display the sum of these values in a single cell. I would then like to
> > > do the same for all rows where ID# is Y.

>
> > > Please help!

>
> > > Many thanks for your time,

>
> > > Paul- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
paulkaye
Guest
Posts: n/a
 
      15th Jan 2008
Ah, thank you for that explanation - now I understand what the formula
is doing. I obviously simplified the spreadsheet description in my
original question but cannot seem to get the correct result. Here is
how I have extended your suggestion:

=SUMPRODUCT((AND($C$6:$C$1000="103",$D$6:$D$1000="120ml")*($I$6:$I
$1000)))

As you can see, there are two conditions. I want to add up the values
in column I for product 103 (column C) in size 120ml (column D). I'm
getting zero as the result every time. Is there an error in the
formula I've entered here? Just for your info, I'm intending to extend
the formula further (by using INDIRECT to reference the formula and
size names) once I've got this correct.

Many thanks for your time,

Paul

On Jan 14, 12:58 pm, Pete_UK <pashu...@auditel.net> wrote:
> The first part of the formula (A1:A100="X") is in fact a conditional
> statement which will check in turn if A1="X", A2="X", A3="X" etc and
> return TRUE or FALSE as appropriate, which will be interpreted as 1 or
> 0 respectively. Hence:
>
> (1 or 0)*(B1-C1)
> +(1 or 0)*(B2-C2)
> +(1 or 0)*(B3-C3)
>
> will give (Bx - Cx) only where Ax = "X", which is what you want.
>
> Check that you have proper numbers in columns B and C, and not text
> values. An alternative that you might like to try is:
>
> =SUMPRODUCT(--(A1:A100="X"),(B1:B100-C1:C100))
>
> Hope this helps.
>
> Pete
>
> On Jan 14, 10:08 am, paulkaye <paulmjk...@gmail.com> wrote:
>
> > Hi,

>
> > I got a #VALUE! error.

>
> > I don't quite understand the formula - it looks like it does something
> > like:

>
> > A1*(B1-C1)
> > +A2*(B2-C2)
> > +A3*(B3-C3)
> > ...

>
> > Could you explain? I was expecting to do something with IF statements!

>
> > Many thanks again for your time,

>
> > Paul

>
> > On Jan 14, 11:37 am, Pete_UK <pashu...@auditel.net> wrote:

>
> > > Try these:

>
> > > =SUMPRODUCT((A1:A100="X")*(B1:B100-C1:C100))

>
> > > =SUMPRODUCT((A1:A100="Y")*(B1:B100-C1:C100))

>
> > > Adjust column ranges to suit, but you can't have a complete column
> > > (unless you have XL2007).

>
> > > Hope this helps.

>
> > > Pete

>
> > > On Jan 14, 6:47 am, paulkaye <paulmjk...@gmail.com> wrote:

>
> > > > Hi,
> > > > This one is getting the better of me, even though I know I should be
> > > > able to figure it out myself!:

>
> > > > I have two columns of data: B and C.
> > > > I have one column of ID#: A

>
> > > > I would like to subtract C from B in all rows where ID# is X and
> > > > display the sum of these values in a single cell. I would then like to
> > > > do the same for all rows where ID# is Y.

>
> > > > Please help!

>
> > > > Many thanks for your time,

>
> > > > Paul- Hide quoted text -

>
> > - Show quoted text -


 
Reply With Quote
 
Pete_UK
Guest
Posts: n/a
 
      15th Jan 2008
Hi Paul,

no need for the AND, as the * does the same job - you can re-write it
as:

=SUMPRODUCT(($C$6:$C$1000="103")*($D$6:$D$1000="120ml")*($I$6:$I
$1000))

The only other concern I have is whether your product codes are
numbers or text in column C - you might have to write the first bit
as:

($C$6:$C$1000=103)

You can put the values in different cells, eg M1, N1, and then your
formula becomes:

=SUMPRODUCT(($C$6:$C$1000=M1)*($D$6:$D$1000=N1)*($I$6:$I$1000))

This way you can change the values easily without having to change the
formula. Also, if the formula is in cell O1 then you can put other
values in M and N and copy the formula down.

Hope this helps.

Pete

On Jan 15, 8:27*am, paulkaye <paulmjk...@gmail.com> wrote:
> Ah, thank you for that explanation - now I understand what the formula
> is doing. I obviously simplified the spreadsheet description in my
> original question but cannot seem to get the correct result. Here is
> how I have extended your suggestion:
>
> =SUMPRODUCT((AND($C$6:$C$1000="103",$D$6:$D$1000="120ml")*($I$6:$I
> $1000)))
>
> As you can see, there are two conditions. I want to add up the values
> in column I for product 103 (column C) in size 120ml (column D). I'm
> getting zero as the result every time. Is there an error in the
> formula I've entered here? Just for your info, I'm intending to extend
> the formula further (by using INDIRECT to reference the formula and
> size names) once I've got this correct.
>
> Many thanks for your time,
>
> Paul
>
> On Jan 14, 12:58 pm, Pete_UK <pashu...@auditel.net> wrote:
>
>
>
> > The first part of the formula (A1:A100="X") is in fact a conditional
> > statement which will check in turn if A1="X", A2="X", A3="X" etc and
> > return TRUE or FALSE as appropriate, which will be interpreted as 1 or
> > 0 respectively. Hence:

>
> > *(1 or 0)*(B1-C1)
> > +(1 or 0)*(B2-C2)
> > +(1 or 0)*(B3-C3)

>
> > will give (Bx - Cx) only where Ax = "X", which is what you want.

>
> > Check that you have proper numbers in columns B and C, and not text
> > values. An alternative that you might like to try is:

>
> > =SUMPRODUCT(--(A1:A100="X"),(B1:B100-C1:C100))

>
> > Hope this helps.

>
> > Pete

>
> > On Jan 14, 10:08 am, paulkaye <paulmjk...@gmail.com> wrote:

>
> > > Hi,

>
> > > I got a #VALUE! error.

>
> > > I don't quite understand the formula - it looks like it does something
> > > like:

>
> > > * A1*(B1-C1)
> > > +A2*(B2-C2)
> > > +A3*(B3-C3)
> > > ...

>
> > > Could you explain? I was expecting to do something with IF statements!

>
> > > Many thanks again for your time,

>
> > > Paul

>
> > > On Jan 14, 11:37 am, Pete_UK <pashu...@auditel.net> wrote:

>
> > > > Try these:

>
> > > > =SUMPRODUCT((A1:A100="X")*(B1:B100-C1:C100))

>
> > > > =SUMPRODUCT((A1:A100="Y")*(B1:B100-C1:C100))

>
> > > > Adjust column ranges to suit, but you can't have a complete column
> > > > (unless you have XL2007).

>
> > > > Hope this helps.

>
> > > > Pete

>
> > > > On Jan 14, 6:47 am, paulkaye <paulmjk...@gmail.com> wrote:

>
> > > > > Hi,
> > > > > This one is getting the better of me, even though I know I should be
> > > > > able to figure it out myself!:

>
> > > > > I have two columns of data: B and C.
> > > > > I have one column of ID#: A

>
> > > > > I would like to subtract C from B in all rows where ID# is X and
> > > > > display the sum of these values in a single cell. I would then like to
> > > > > do the same for all rows where ID# is Y.

>
> > > > > Please help!

>
> > > > > Many thanks for your time,

>
> > > > > Paul- Hide quoted text -

>
> > > - Show quoted text -- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
paulkaye
Guest
Posts: n/a
 
      15th Jan 2008
That's great - the whole thing works like a charm!

Thank you!

Paul

On Jan 15, 11:21 am, Pete_UK <pashu...@auditel.net> wrote:
> Hi Paul,
>
> no need for the AND, as the * does the same job - you can re-write it
> as:
>
> =SUMPRODUCT(($C$6:$C$1000="103")*($D$6:$D$1000="120ml")*($I$6:$I
> $1000))
>
> The only other concern I have is whether your product codes are
> numbers or text in column C - you might have to write the first bit
> as:
>
> ($C$6:$C$1000=103)
>
> You can put the values in different cells, eg M1, N1, and then your
> formula becomes:
>
> =SUMPRODUCT(($C$6:$C$1000=M1)*($D$6:$D$1000=N1)*($I$6:$I$1000))
>
> This way you can change the values easily without having to change the
> formula. Also, if the formula is in cell O1 then you can put other
> values in M and N and copy the formula down.
>
> Hope this helps.
>
> Pete
>
> On Jan 15, 8:27 am, paulkaye <paulmjk...@gmail.com> wrote:
>
> > Ah, thank you for that explanation - now I understand what the formula
> > is doing. I obviously simplified the spreadsheet description in my
> > original question but cannot seem to get the correct result. Here is
> > how I have extended your suggestion:

>
> > =SUMPRODUCT((AND($C$6:$C$1000="103",$D$6:$D$1000="120ml")*($I$6:$I
> > $1000)))

>
> > As you can see, there are two conditions. I want to add up the values
> > in column I for product 103 (column C) in size 120ml (column D). I'm
> > getting zero as the result every time. Is there an error in the
> > formula I've entered here? Just for your info, I'm intending to extend
> > the formula further (by using INDIRECT to reference the formula and
> > size names) once I've got this correct.

>
> > Many thanks for your time,

>
> > Paul

>
> > On Jan 14, 12:58 pm, Pete_UK <pashu...@auditel.net> wrote:

>
> > > The first part of the formula (A1:A100="X") is in fact a conditional
> > > statement which will check in turn if A1="X", A2="X", A3="X" etc and
> > > return TRUE or FALSE as appropriate, which will be interpreted as 1 or
> > > 0 respectively. Hence:

>
> > > (1 or 0)*(B1-C1)
> > > +(1 or 0)*(B2-C2)
> > > +(1 or 0)*(B3-C3)

>
> > > will give (Bx - Cx) only where Ax = "X", which is what you want.

>
> > > Check that you have proper numbers in columns B and C, and not text
> > > values. An alternative that you might like to try is:

>
> > > =SUMPRODUCT(--(A1:A100="X"),(B1:B100-C1:C100))

>
> > > Hope this helps.

>
> > > Pete

>
> > > On Jan 14, 10:08 am, paulkaye <paulmjk...@gmail.com> wrote:

>
> > > > Hi,

>
> > > > I got a #VALUE! error.

>
> > > > I don't quite understand the formula - it looks like it does something
> > > > like:

>
> > > > A1*(B1-C1)
> > > > +A2*(B2-C2)
> > > > +A3*(B3-C3)
> > > > ...

>
> > > > Could you explain? I was expecting to do something with IF statements!

>
> > > > Many thanks again for your time,

>
> > > > Paul

>
> > > > On Jan 14, 11:37 am, Pete_UK <pashu...@auditel.net> wrote:

>
> > > > > Try these:

>
> > > > > =SUMPRODUCT((A1:A100="X")*(B1:B100-C1:C100))

>
> > > > > =SUMPRODUCT((A1:A100="Y")*(B1:B100-C1:C100))

>
> > > > > Adjust column ranges to suit, but you can't have a complete column
> > > > > (unless you have XL2007).

>
> > > > > Hope this helps.

>
> > > > > Pete

>
> > > > > On Jan 14, 6:47 am, paulkaye <paulmjk...@gmail.com> wrote:

>
> > > > > > Hi,
> > > > > > This one is getting the better of me, even though I know I should be
> > > > > > able to figure it out myself!:

>
> > > > > > I have two columns of data: B and C.
> > > > > > I have one column of ID#: A

>
> > > > > > I would like to subtract C from B in all rows where ID# is X and
> > > > > > display the sum of these values in a single cell. I would then like to
> > > > > > do the same for all rows where ID# is Y.

>
> > > > > > Please help!

>
> > > > > > Many thanks for your time,

>
> > > > > > Paul- Hide quoted text -

>
> > > > - Show quoted text -- Hide quoted text -

>
> > - Show quoted text -


 
Reply With Quote
 
Pete_UK
Guest
Posts: n/a
 
      15th Jan 2008
You're welcome, Paul - glad it worked for you.

Pete

On Jan 15, 2:51*pm, paulkaye <paulmjk...@gmail.com> wrote:
> That's great - the whole thing works like a charm!
>
> Thank you!
>
> Paul
>
> On Jan 15, 11:21 am, Pete_UK <pashu...@auditel.net> wrote:
>
>
>
> > Hi Paul,

>
> > no need for the AND, as the * does the same job - you can re-write it
> > as:

>
> > =SUMPRODUCT(($C$6:$C$1000="103")*($D$6:$D$1000="120ml")*($I$6:$I
> > $1000))

>
> > The only other concern I have is whether your product codes are
> > numbers or text in column C - you might have to write the first bit
> > as:

>
> > ($C$6:$C$1000=103)

>
> > You can put the values in different cells, eg M1, N1, and then your
> > formula becomes:

>
> > =SUMPRODUCT(($C$6:$C$1000=M1)*($D$6:$D$1000=N1)*($I$6:$I$1000))

>
> > This way you can change the values easily without having to change the
> > formula. Also, if the formula is in cell O1 then you can put other
> > values in M and N and copy the formula down.

>
> > Hope this helps.

>
> > Pete

>
> > On Jan 15, 8:27 am, paulkaye <paulmjk...@gmail.com> wrote:

>
> > > Ah, thank you for that explanation - now I understand what the formula
> > > is doing. I obviously simplified the spreadsheet description in my
> > > original question but cannot seem to get the correct result. Here is
> > > how I have extended your suggestion:

>
> > > =SUMPRODUCT((AND($C$6:$C$1000="103",$D$6:$D$1000="120ml")*($I$6:$I
> > > $1000)))

>
> > > As you can see, there are two conditions. I want to add up the values
> > > in column I for product 103 (column C) in size 120ml (column D). I'm
> > > getting zero as the result every time. Is there an error in the
> > > formula I've entered here? Just for your info, I'm intending to extend
> > > the formula further (by using INDIRECT to reference the formula and
> > > size names) once I've got this correct.

>
> > > Many thanks for your time,

>
> > > Paul

>
> > > On Jan 14, 12:58 pm, Pete_UK <pashu...@auditel.net> wrote:

>
> > > > The first part of the formula (A1:A100="X") is in fact a conditional
> > > > statement which will check in turn if A1="X", A2="X", A3="X" etc and
> > > > return TRUE or FALSE as appropriate, which will be interpreted as 1 or
> > > > 0 respectively. Hence:

>
> > > > *(1 or 0)*(B1-C1)
> > > > +(1 or 0)*(B2-C2)
> > > > +(1 or 0)*(B3-C3)

>
> > > > will give (Bx - Cx) only where Ax = "X", which is what you want.

>
> > > > Check that you have proper numbers in columns B and C, and not text
> > > > values. An alternative that you might like to try is:

>
> > > > =SUMPRODUCT(--(A1:A100="X"),(B1:B100-C1:C100))

>
> > > > Hope this helps.

>
> > > > Pete

>
> > > > On Jan 14, 10:08 am, paulkaye <paulmjk...@gmail.com> wrote:

>
> > > > > Hi,

>
> > > > > I got a #VALUE! error.

>
> > > > > I don't quite understand the formula - it looks like it does something
> > > > > like:

>
> > > > > * A1*(B1-C1)
> > > > > +A2*(B2-C2)
> > > > > +A3*(B3-C3)
> > > > > ...

>
> > > > > Could you explain? I was expecting to do something with IF statements!

>
> > > > > Many thanks again for your time,

>
> > > > > Paul

>
> > > > > On Jan 14, 11:37 am, Pete_UK <pashu...@auditel.net> wrote:

>
> > > > > > Try these:

>
> > > > > > =SUMPRODUCT((A1:A100="X")*(B1:B100-C1:C100))

>
> > > > > > =SUMPRODUCT((A1:A100="Y")*(B1:B100-C1:C100))

>
> > > > > > Adjust column ranges to suit, but you can't have a complete column
> > > > > > (unless you have XL2007).

>
> > > > > > Hope this helps.

>
> > > > > > Pete

>
> > > > > > On Jan 14, 6:47 am, paulkaye <paulmjk...@gmail.com> wrote:

>
> > > > > > > Hi,
> > > > > > > This one is getting the better of me, even though I know I should be
> > > > > > > able to figure it out myself!:

>
> > > > > > > I have two columns of data: B and C.
> > > > > > > I have one column of ID#: A

>
> > > > > > > I would like to subtract C from B in all rows where ID# is X and
> > > > > > > display the sum of these values in a single cell. I would thenlike to
> > > > > > > do the same for all rows where ID# is Y.

>
> > > > > > > Please help!

>
> > > > > > > Many thanks for your time,

>
> > > > > > > Paul- Hide quoted text -

>
> > > > > - Show quoted text -- Hide quoted text -

>
> > > - Show quoted text -- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help, please, adding on to items in a column... Uncle Vinnie Microsoft Excel Discussion 5 10th Jul 2008 04:02 AM
Adding items in one row if criteria in another column is met. migpics Microsoft Excel Programming 0 7th May 2008 09:20 PM
Adding Subject Column to Sent Items Folder =?Utf-8?B?am9lbGhvaA==?= Microsoft Outlook Installation 2 26th Apr 2006 02:46 PM
ListView Column's AddRange is adding the wrong array type of items in InitializeComponent jrhoads23@hotmail.com Microsoft Dot NET Framework Forms 1 3rd May 2005 09:33 AM
Adding items to the second column of a list box mika Microsoft Excel Programming 3 25th Nov 2003 12:05 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:33 AM.