+ Reply to Thread
Results 1 to 11 of 11

Excel 2007 : Count based on year in a row of dates

  1. #1
    Registered User
    Join Date
    01-20-2011
    Location
    Washington, USA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Count based on year in a row of dates

    I have an Excel file that lists a date that corresponds to each time a photo was used. I need to count the usage based on a specified year, but haven't found the right function to do this. Here's a rough example:

    Photo name | Usage | Date(C | Date(D) | Date(E)

    MyDog.jpg | #here | 1/1/2010 | 3/7/2010 | 1/21/2011

    The usage column needs a function that counts the number of uses in 2010 based on columns C, D and E (there are actually columns out to Z). So, in this example, the number in the usage column should be 2.

    I've tried COUNTIF and SUMPRODUCT, but so far have been unsuccessful. Thanks in advance for any help you can provide.

    Kevin
    Last edited by Dadoo; 01-25-2011 at 02:51 PM.

  2. #2
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Count based on year in a row of dates

    Based strictly on the example you gave:

    =COUNTIF(C2:E2,">="&DATE(2010,1,1))-COUNTIF(C2:E2,">="&DATE(2011,1,1))

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Count based on year in a row of dates

    The above is backwards compatible with versions prior to XL2007- the below is not:

    Please Login or Register  to view this content.
    If you're not using XL2007 it would be best to update your profile accordingly (and/or state version requirements in question)

  4. #4
    Registered User
    Join Date
    01-20-2011
    Location
    Washington, USA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Count based on year in a row of dates

    I've tried both of the functions shown here, but can't get them to work. Clicking the "function wizard" button indicates that the &DATE(2010, 1, 1) is evaluating to a serial number rather than a date. I suppose that is what it is designed to do, but the date fields are in traditional mm/dd/yyyy format.

    Seems I also need to deal with a format problem to get everything to work?

    BTW, my profile indicates Excel 2007, which is correct. Thanks!

  5. #5
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Count based on year in a row of dates

    Are the dates actually dates or are they text values that look like dates?
    The formulas assume actual dates.

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Count based on year in a row of dates

    Quote Originally Posted by Dadoo View Post
    DATE(2010, 1, 1) is evaluating to a serial number rather than a date.
    To be clear - in XL Dates are just Serial Numbers (Time being Decimal) - the Format applied to the Number determines the appearance (ie number or date)

    I'd suggest posting a sample file to avoid further confusion.

  7. #7
    Registered User
    Join Date
    01-20-2011
    Location
    Washington, USA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Count based on year in a row of dates

    I've attached a sample file. Thanks again!

    Kevin

    P.S. Just did a test on the Excel file. Looks like column D is a number, but columns E thru G are not. They came from the same source file, but perhaps something I did to add delimiters to the file changed the format of every field after D or something. So perhaps the crux of the problem is to get all of the date rows into the same format?
    Attached Files Attached Files
    Last edited by Dadoo; 01-24-2011 at 08:28 PM.

  8. #8
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Count based on year in a row of dates

    The dates in col D are actual dates
    The "dates" in cols E to G are not - they are text and they have leading spaces.
    Last edited by Cutter; 01-24-2011 at 08:31 PM.

  9. #9
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Count based on year in a row of dates

    Yes - that would be the crux of the problem.

  10. #10
    Registered User
    Join Date
    01-20-2011
    Location
    Washington, USA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Count based on year in a row of dates

    Thanks to you and DonkeyOte, I went back and exported my data again, this time eliminating the spaces that preceded all but the data in row D. This resulted in all of the dates being evaluated as actual dates rather than as text. This made the COUNTIFS suggested here work like a charm. I removed the "=" from the second part of the COUNTIF to make it a true count of only 2010 entries, but other than that minor, minor tweak it worked like an absolute charm.

    Thanks much to both of you!

  11. #11
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Count based on year in a row of dates

    You're quite welcome. Don't forget to mark your post as SOLVED.
    (click on FAQ at top of page for directions)

+ 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