+ Reply to Thread
Results 1 to 22 of 22

how to sum cells meeting row & column condition

  1. #1
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    119

    how to sum cells meeting row & column condition

    Hi, please find the sample sheet attached.

    I want to sum the cells in a row range only if meeting a condition in row and column as well. I tried it with 'Sumproduct' but getting #value error pls help !

    Thanks.

    Divya..............
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    05-21-2013
    Location
    UK
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    86

    Re: how to sum cells meeting row & column condition

    Not sure exactly what the rest of your data may look like of how the data may grow but my first thought was something like:
    =SUMIF(F1:F10,"Late",E1:E10)+SUMIF(K1:K10,"Late",J1:J10)+SUMIF(P1:P10,"Late",O1:O10)

  3. #3
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    119

    Re: how to sum cells meeting row & column condition

    Hi Duffry, this mite not be suitable as my data ranges from the date feild 26/06/13 to 25/07/13. pls give me some other suitable options

  4. #4
    Forum Contributor
    Join Date
    06-26-2013
    Location
    LAX
    MS-Off Ver
    Excel 2007,Excel 2010
    Posts
    363

    Re: how to sum cells meeting row & column condition

    Hi Divya,

    Try this...in T3

    =SUMPRODUCT(--(F3>0)+(K3>0)+(P3>0),SUM(Q3:S3)/3)

    You might even get ODD results, since the lay hours is in HH.MM.SS AM/PM format. I assume you actually need those in HH:MM ( Hour and Minutes) which you will enter manually.

    Try

  5. #5
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    119

    Re: how to sum cells meeting row & column condition

    Dear Elayaz, u are almost rite bt actualy mistaken.. my requirement is to get the lay hrs sum value in column Q, R & S, if it meets the condition given in 'Attn' remarks. Like if the 'Attn' remarks has Late then the respective lay hrs shud be added in column Q and if the 'Attn' remarks has (P)then the respective lay hrs shud be added in column R respectively

    i worked with this formula

    =Sumproduct((B2:P2="Lay Hrs")*(B3:P3)*(B3:P3="Late")) but getting a value error.. think it shud be worked even better..

    kindly help !

  6. #6
    Registered User
    Join Date
    05-21-2013
    Location
    UK
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    86

    Re: how to sum cells meeting row & column condition

    Still not sure quite what you're after.

    Are you looking for something that will sum all values in any Lay Hrs column when there are any values in Attn columns?
    - This is what eleyaz's formula is doing (as I understand it)

    The formula I posted is just to add up any value in a Lay Hrs column where the next Attn column has the value "Late". This seemed to be the formula required for cell Q3.
    You would need to adjust the formula for cells R3 and S3 to look for "(P)" and "SR".

    Quote Originally Posted by divi123 View Post
    my data ranges from the date feild 26/06/13 to 25/07/13.
    How does the data set grow, are there further rows or columns?
    Can you upload a wider sample to see?
    What errors are you experiencing?


    [edit] Your reply came while I wrote mine

    Quote Originally Posted by divi123 View Post
    =Sumproduct((B2:P2="Lay Hrs")*(B3:P3)*(B3:P3="Late")) but getting a value error.. think it shud be worked even better..
    Something like this might work better (in that it is looking in the correct places) but I think the #VALUE error is coming from 'multiplying' TRUE/FALSE results with non-numeric values (in the *(B3:P3) bit).
    =SUMPRODUCT((B2:P2="Lay Hrs")*(OFFSET(B3:P3,0,1)="Late")*(B3:P3))
    or simpler
    =SUMPRODUCT((B2:P2="Lay Hrs")*(C3:Q3="Late")*(B3:P3))
    Not sure how you are going to get around that if you're set on using SUMPRODUCT.
    Last edited by duffry; 07-08-2013 at 07:07 AM.

  7. #7
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    119

    Re: how to sum cells meeting row & column condition

    duffry,

    i'm still getting this #value error when using both the formulas u suggested.. please come up with other options if any..

    it is as simple as that i want to sum up the late hrs falling under 'Late', (P) and 'SR' respectively

  8. #8
    Registered User
    Join Date
    05-21-2013
    Location
    UK
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    86

    Re: how to sum cells meeting row & column condition

    Quote Originally Posted by divi123 View Post
    i'm still getting this #value error when using both the formulas u suggested.. please come up with other options if any..
    Yes, as I said, unless you have numberic or TRUE/FALSE values it will generate that error.

    Quote Originally Posted by divi123 View Post
    it is as simple as that i want to sum up the late hrs falling under 'Late', (P) and 'SR' respectively
    Lets be clear, there are no hours under those values. As I understand it you want to sum values based on two criteria: they fall under the value "Lay Hrs" AND they fall before 'Late', '(P)' and 'SR' respectively. As far as I can see the formula I first suggested will work for you if you add further rows of data in the same format (and adjust based on the cell you put it on and number of rows of data).

    Again, I ask:
    How does the data set grow, are there further rows or columns?
    Can you upload a wider sample to see?
    What errors are you experiencing?

  9. #9
    Forum Contributor
    Join Date
    06-26-2013
    Location
    LAX
    MS-Off Ver
    Excel 2007,Excel 2010
    Posts
    363

    Re: how to sum cells meeting row & column condition

    Not sure I got you right this time at least. I assume you are trying to add the lay hours time based on the value SR or (P) or Late.

    If that's correct simple if solution will work. Sure there are much more easier solutions around. But I wanted to know if this solves your need or We are in the wrong direction.

    See the attached file.

    ---

    If my reply helped, Please add reputation (click on the star below the post)
    If the reply solves your problem, Don't forget to mark the thread as "Solved" (Thread Tools->Mark thread as Solved)
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    119

    Re: how to sum cells meeting row & column condition

    Dear Duffry, u rightly got my requirement bt please be noted that my data ranges from column F to FX for which this formula would not be suitable. kindly help with other options if any

  11. #11
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    119

    Re: how to sum cells meeting row & column condition

    Please find the actual data sheet attached for your workings
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    05-21-2013
    Location
    UK
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    86

    Re: how to sum cells meeting row & column condition

    Ok, that makes it interesting.

    You can use offset arrays in SUMPRODUCT yo make it work, though you do need to use an array formula (Ctrl + Shift + Enter) to be able to discount any non-numeric values in the data.

    For the "Late" value you can put this anywhere:
    =SUMPRODUCT((E4:FW4="Attn")*(E5:FW119="Late")*(D4:FV4="Late Hrs")*IF(ISNUMBER(D5:FV119),(D5:FV119),0))
    Remember to use Ctrl + Shift + Enter, not just enter.

    That'll catch and sum every value in a column titled "Late Hrs" with a value "Late" in the cell to the right of it in a column titled "Attn", and sum them together.
    Obviously you would need to adjust it to handle more rows of data and for the "(P)" and "SR" values.

    If you need totals row by row then say, cos I haven't considered that.

  13. #13
    Forum Contributor
    Join Date
    06-26-2013
    Location
    LAX
    MS-Off Ver
    Excel 2007,Excel 2010
    Posts
    363

    Re: how to sum cells meeting row & column condition

    Oh yes. If you need to sum much data like the data in your sample sheet, you need to go with Sum product.

    duffry formula should work well for your need.

    ----

  14. #14
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    119

    Re: how to sum cells meeting row & column condition

    Dear Duffry & Elayaz.. thanks for the suggestion bt think it shud be worked a little more as i'm not getting the results. also kindly explain me about the ranges u have taken bcoz the data ranges from D to FV only yet why FW is taken into consideration and also the need of adding IF(ISNUMBER(D5:FV119),(D5:FV119),0)) in the array.. Your explanation wud help me for better understanding.

    Thanks,

    Divya

  15. #15
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    119

    Re: how to sum cells meeting row & column condition

    Guys thanks, i got the results wen i corrected the workings little

    =SUMPRODUCT((E$4:FW$4="Attn")*(E5:FW5="Late")*(D$4:FV$4="Late Hrs")*IF(ISNUMBER(D5:FV5),(D5:FV5),0))
    (Ctrl+shift+enter)

    it perfectly suits my requirement

    bt do explain me the purpose of using IF & ISnumber here..

    Also tel me y its taken from 'E' wen the data ranges from "D" (E$4:FW$4="Attn")*(E5:FW5="Late")
    Last edited by divi123; 07-09-2013 at 07:46 AM.

  16. #16
    Registered User
    Join Date
    05-21-2013
    Location
    UK
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    86

    Re: how to sum cells meeting row & column condition

    Good stuff. yes, that would be the way to get the value for each row rather than the whole data set. GJ.

    Each thing that you are multiplying together within the SUMPRODUCT produces an array of elements. The first two arrays are the ones to check for "Late" in the cell one to the right of the cells you want to add up and so are offset one cell to the right compared to the other arrays. This means that when evaluated they will have their true/false values in the same relative positions as the other arrays.

    The IF/ISNUMBER part is to deal with the #VALUE response error, as described in post 6 above. All the values in the arrays need to be either true/false or numbers. This part simply checks the values in the relevant array and replaces them with a zero if not a number. The other arrays do not need this validation because you are not multiplying the values, but simply making a logical comparison of each one.

    HTH
    Last edited by duffry; 07-09-2013 at 02:40 AM.
    If I've helped or inspired, please click the star.

  17. #17
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    119

    Re: how to sum cells meeting row & column condition

    Thanks bt duffry could u be simple and even more clear, bcoz i'm still not clear abt the need of IF/Isnumber used here

    =SUMPRODUCT((E$4:FW$4="Attn")*(E5:FW5="Late")*(D$4:FV$4="Late Hrs")*IF(ISNUMBER(D5:FV5),(D5:FV5),0))
    (Ctrl+shift+enter)

    bt it perfectly suits my requirement

    Also tel me why its taken from 'E:FW' when the actual data ranges from "D:FV" (E$4:FW$4="Attn")*(E5:FW5="Late")

    bcoz i'm not getting the desired results when i change the ranges this way

    =SUMPRODUCT((D$4:FV$4="Attn")*(D5:FV5="SR")*(D$4:FV$4="Late Hrs")*IF(ISNUMBER(D5:FV5),(D5:FV5),0))


    pls look into

  18. #18
    Registered User
    Join Date
    05-21-2013
    Location
    UK
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    86

    Re: how to sum cells meeting row & column condition

    Ok, I don't have the facility to upload a sheet or image at the moment (or use Excel for that matter) so I'll try explaining without them.

    Imaging a simple sheet with the values a, b & c in the first three cells of the first row and the numbers 1, 2 & 3 in the first three cells of the second row.

    A B C
    1 2 3

    Then elsewhere you have the formula:
    =SUMPRODUCT((B$1:D$1="C")*(B2:D2=3)*(A$1:C$1="B")*(A2:C2))

    The first pair of arrays would return as:
    {FALSE,TRUE,FALSE}
    {FALSE,TRUE,FALSE}
    This is because they are finding the desired values of "C" and 3 in the second position of the identified range in both cases.

    The third array would return:
    {FALSE,TRUE,FALSE}

    The fourth:
    {1,2,3}

    So the first two are offset to the right by one place so they check the cells one to the right of the desired return (2, in this example) but have their TRUE results in the same relative position in the returned arrays. This is important as when the arrays are ANDed together ("*") they do so like this:
    FALSE * FALSE * FALSE * 1 = 0*0*0*1 = 0
    TRUE * TRUE * TRUE * 2 = 1*1*1*2 = 2
    FALSE * FALSE * FALSE * 3 = 0*0*0*3 = 0

    Hope that makes sense. Have to leave the house for a bit so will come back for part 2 later.

  19. #19
    Registered User
    Join Date
    05-21-2013
    Location
    UK
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    86

    Re: how to sum cells meeting row & column condition

    Right, the IF/ISNUMBER part...

    Because we are multiplying values together then this needs to be something Excel is happy doing.
    2 * 2 = 4, Excel is happy with this.
    TRUE * 2 = 2, Excel can do this (when the TRUE/FALSE is a boolean value and not a string) because it evaluates TRUE as 1 and FALSE as 0.
    "Purple" * 2 = #VALUE, Excel can't work this out as it doesn't make much sense. The #VALUE return lets you know what's going on.

    You were returning the #VALUE error initially because part of the mathematical process you were asking for involved multiplying a number by a string. So how do we get rid of string?

    The ISNUMBER function tests whether the argument supplied is a number or not. Because this is an array formula we can pass it an array of values for it to work through. In this case we want to have it evaluate the final array of the values that will be returned, (D5:FV5).

    If we were to have the first three cells of the first row of a sheet contain:
    1,2,F
    and then use the array formula
    {=ISNUMBER(A1:C1)}
    it would return:
    {TRUE,TRUE,FALSE}

    If we then put that in an IF function and let the "if TRUE" result be our original array and the "if FALSE" result be a zero...
    {=if(ISNUMBER(A1:C1),(A1:C1),0)}
    ...then the return from this array formula would be...
    {1,2,0}
    ...which can then be evaluated by the other parts of the SUMPRODUCT formula without producing a #VALUE error.
    __________

    How's that?

  20. #20
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    119

    Re: how to sum cells meeting row & column condition

    thanks duffry for the time you shared but please bare with me for some more queries.

    by now i perfectly understand the need of IF/Isnumber here but still no so clear abt why the ranges are taken B:D when the actual data ranges from A:c
    pls explain

    So the first two are offset to the right by one place so they check the cells one to the right of the desired return (2, in this example) but have their TRUE results in the same relative position in the returned arrays.

  21. #21
    Registered User
    Join Date
    05-21-2013
    Location
    UK
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    86

    Re: how to sum cells meeting row & column condition

    Ok, so a smaller version of your data could be...

    Total Hrs.....Late Hrs.......Attn
    09:46.........00:13..........Late

    With the formula being
    =SUMPRODUCT((B$1:D$1="Attn")*(B2:D2="Late")*(A$4:C$4="Late Hrs")*IF(ISNUMBER(A5:C5),(A5:C5),0))

    As you say, the data is in range A1:C2 but the first two arrays are populated from B1:D2, offset from the data by one cell to the right.
    In this case we want to return the 00:13 value in cell B2, we know this because of three things:
    1, it is in a column titled "Late Hrs"
    2, it is one cell to the left of the word "late"
    3, this word 'late' is in a column titled "Attn"

    The sumproduct is evaluating these three things as such:
    =SUMPRODUCT((3)*(2)*(1)*(value))

    (B$1:D$1="Attn") carries out the following tests:
    "Late Hrs"="Attn"
    "Attn"="Attn"
    ""="Attn"

    Which evaluates to:
    FALSE
    TRUE
    FALSE

    (B2:D2="Late") carries out the following tests:
    "00:13"="Late"
    "Late"="Late"
    ""="Late"

    Which also evaluates to:
    FALSE
    TRUE
    FALSE

    (A$4:C$4="Late Hrs") carries out the following tests:
    "Total Hrs"="Late Hrs"
    "Late Hrs"="Late Hrs"
    "Attn"="Late Hrs"

    Which also evaluates to:
    FALSE
    TRUE
    FALSE

    Finally the last part returns the following values (the times will actually be decimal serial number, but don't worry about that for this):
    09:46
    00:13
    0

    So the whole thing evaluates as:
    FALSE * FALSE * FALSE * 09:46
    TRUE * TRUE * TRUE * 00:13
    FALSE * FALSE * FALSE * 0

    Which becomes:
    0 * 0 * 0 * 09:46
    1 * 1 * 1 * 00:13
    0 * 0 * 0 * 0

    Which becomes:
    0
    00:13
    0

    Which are added together to get the 00:13 you wanted.


    Ok, so you see how all the TRUEs line up? If they didn't then you wouldn't get the right result. You need the second value of each to be TRUE. If we were to set up the first two tests in the same column range as the third and fourth then it would be the third value that would be true in each case. So shifting the range once cell to the right means we can perform the test on the cells one to the right of the value cell and have the array results 'align' to produce the right answer.


    TL:DR
    To validate a test on a cell one to the right you want to offset the validation range one to the right as well.

  22. #22
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    119

    Re: how to sum cells meeting row & column condition

    Superb it is.. thanks duffry...

    thank you for such a detailed explanation.. thanks a ton!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1