+ Reply to Thread
Results 1 to 14 of 14

Counting values in 2 columns

  1. #1
    Registered User
    Join Date
    03-25-2008
    Posts
    10

    Counting values in 2 columns

    i have been looking at excel formulas all night and cannot get this to work.

    I have column A, which contains either the values ENG or HK. Column B contains values P or NP. i need a formula, for a separate sheet, that will count the combination of HK and P values, HK and NP vales, ENG and P values, ENG and NP values.

    i have tried an If/And function, i have tried a lookup array function, and a countif function. i cannot seem to get it to work, does anyone have any ideas to get it to return a count value of those 4 combinations (in separate cells)?

  2. #2
    Forum Contributor
    Join Date
    10-14-2004
    Location
    San Diego, CA
    Posts
    213
    Hello kethyar:

    Paste this in cell C1 on Sheet2 and type the letters ENG in cell D1.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    03-25-2008
    Posts
    10
    i tried this, but this returns me a weird value. the first time i got a time value (eh, the only information in my sheet, besides headers, are the NP, P, ENG and HK). when i played with it a bit i got 0 (there are 4 values that are HK and P together) and then any further playing with the formula gets me an error where it highlights the entire thing.

  4. #4
    Forum Contributor Portuga's Avatar
    Join Date
    02-20-2004
    Location
    Portugal
    MS-Off Ver
    365
    Posts
    852
    Hi,

    You can use the sumproduct formula:

    =SUMPRODUCT((A2:A5000="ENG")*(B2:B5000="P"))

    ...and so on for the remaining combinations.
    Last edited by Portuga; 03-25-2008 at 11:41 PM.
    If you found the solution to your question. Mark the thread as "Solved"
    Thank everyone that helped you with a valid solution by clicking on their

    There is no such thing as a problem, only a temporary lack of a solution

  5. #5
    Forum Contributor
    Join Date
    10-14-2004
    Location
    San Diego, CA
    Posts
    213
    Are the values paired within the same cells?

  6. #6
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326
    You could also try a Pivot Table

  7. #7
    Registered User
    Join Date
    03-25-2008
    Posts
    10
    Pivot Table might work, but i guess im having trouble setting it up, especially with the data section.

    my sheet has many columns on it, but for the formulas im trying to work on, it looks like this

    Dept Time In Time Out Total Time P/NP
    HK 7:30AM 7:45AM 15 P
    ENG 9:34AM 9:53AM 19 P
    ENG 11:30AM 12:00PM 30 NP
    HK 1:23PM 1:30PM 7 P
    HK 2:37PM 2:45PM 8 P

    etc, etc. it goes on.

    on Sheet 2, is a summary

    HK
    # of P's Total Time Average

    HK
    # of NP's Total Time Average

    ENG
    #of P's Total Time Average

    ENG
    # of NP's Total Time Average


    does this make any more sense? i am trying to calculate how many HK + P's for Sheet2, and then the number of HK + NP's. just a count function, not a sum or anything. there are 3 HK + P's, but i cannot find a function that calculates this (the actual sheet of course will have many more values).

    in using a Pivot Table, for the data field, do i need to have a separate column or row with the calculation in it? i cannot seem to figure out what type of calculation i need or how to work that out. i thought a simple IF/AND function would work, but it doesnt seem to be

    i see the spacing has completely gone to heck too =/
    Last edited by kethyar; 03-26-2008 at 03:13 PM.

  8. #8
    Forum Contributor Portuga's Avatar
    Join Date
    02-20-2004
    Location
    Portugal
    MS-Off Ver
    365
    Posts
    852
    Hi,

    You can use the sumproduct formula:

    =SUMPRODUCT((A2:A5000="ENG")*(B2:B5000="P"))

    ...and so on for the remaining combinations.


    Deja vu?

  9. #9
    Registered User
    Join Date
    03-25-2008
    Posts
    10
    ok, i think i have a pivot table working. the only problem is that i see they don't automatically update. im attempting to create a template, with formulas, for other people in my department to use. and since they don't understand excel, i would like something that automatically updates as you input the information (the values HK, P, etc and the times), which is why i was looking for a IF/AND or something similar that might work. does anyone have any suggestions, or will it be too complicated to try to get that?

  10. #10
    Forum Contributor Portuga's Avatar
    Join Date
    02-20-2004
    Location
    Portugal
    MS-Off Ver
    365
    Posts
    852
    I dont think there is a way to automatically refresh the pivot (maybe with some vb code that triguers an event whe data is entered in the source sheet)

    possible workarounds:

    1 - create a refresh button (its what I do) that when clicked refreshes the pivot.
    2 - enable "pivot refresh when document is opened" in the pivot configuration.
    3- tell users to when in doubt always refresh table or (click refresh button)

  11. #11
    Registered User
    Join Date
    03-25-2008
    Posts
    10
    Quote Originally Posted by Portuga
    Hi,

    You can use the sumproduct formula:

    =SUMPRODUCT((A2:A5000="ENG")*(B2:B5000="P"))

    ...and so on for the remaining combinations.


    Deja vu?

    i read this, and thought it was actually multiplying the values so i didn't try it. of course, when i do it works (im an idiot).

    anyway, after this, im trying to calculate the time based on HK + P, etc. i used IF(sumproduct((etc)),sum(range)) but i keep coming up with a negative number. does this not work, or is there a better way to sum the Total Time values of just HK + P, etc?

  12. #12
    Forum Contributor Portuga's Avatar
    Join Date
    02-20-2004
    Location
    Portugal
    MS-Off Ver
    365
    Posts
    852
    Hi,
    Yes, the sumproduct formula can be deceiving in appearence.

    You can try the following sumproduct (in this case, by adding an extra parameter to the sumproduct formula, it sums it (Yes, sum!)

    Please Login or Register  to view this content.
    I´m assuming the Time results are in column C.
    I know this works on numerical values, dont know how it reacts to time (even though times are just numbers... formated as time)

  13. #13
    Registered User
    Join Date
    03-25-2008
    Posts
    10
    it doesnt react well to time. i keep getting a number that is less than 1 (the Total Time values are all real numbers, 15 min, etc). im wondering if this has to do with the format. i had to Custom format the time values due to the subtracting value not working unless they were formatted that way.

  14. #14
    Forum Contributor Portuga's Avatar
    Join Date
    02-20-2004
    Location
    Portugal
    MS-Off Ver
    365
    Posts
    852
    Try custom formating the cell where you have the sumproduct formula the same way.

+ 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