+ Reply to Thread
Results 1 to 7 of 7

Applying date range

  1. #1
    Registered User
    Join Date
    10-26-2008
    Location
    dublin
    Posts
    10

    Applying date range

    Hi There

    And if anyone can help out you will have saved my day!

    To explain I have two sets of merged data. On one fixed column I have two different sets of peoples age

    1 - by age grouip eg 25 - 34
    2 - By birth year so 01/02/1983

    I know that person who is born between 1975 and 1984 would fall into the age group 25 - 34

    I want to convert all the birth years into age groups. Its a lot of data (30,000 rows +) in random order

    Does anyone have any idea how I would set this up, as I really want to add "age group" to a pivot table I have

    Any ideas/suggestions really appreciated

    Cheers
    Remo
    Last edited by remo; 05-20-2009 at 04:01 AM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Applying date range

    You could use DATEDIF to compute the age in years base on birth date, and VLOOKUP to translate that to age groups.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Applying date range

    Have some sample data pointing out where you're wanting to do this? (Click GO ADVANCED and use the paperclip icon to attach a workbook sample with appropriate desired results shown).
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Applying date range

    Assuming you have dates in A2 down and a date in D1 (e.g. today's date) at which you want the age then try this formula in B2 copied down

    =MAX(0,FLOOR(DATEDIF(A2,D$1,"y")+5,10)-5)&" - "&FLOOR(DATEDIF(A2,D$1,"y")+5,10)+4

  5. #5
    Registered User
    Join Date
    10-26-2008
    Location
    dublin
    Posts
    10

    [SOLVED]Re: Applying date range

    Thanks everyone for there suggestion, I ended up using Daddylonglengs fix as works for me

  6. #6
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Applying date range

    Hello remo, re your PM

    My suggestion works for identical sized time ranges, i.e. all 10 years. For variable ranges you can use a LOOKUP type formula as shg suggested, e.g. try

    =LOOKUP(DATEDIF(A2,D$1,"y"),{0,18,25,35,45,55,65,75},{"0-17","18-24","25-34","35-44","45-54","55-64","old","really old"})

    the "array constant" {0,18,25,35,45,55,65,75} defines the "lower bound" for each age range and the second array constant {"0-17","18-24","25-34","35-44","45-54","55-64","old","really old"} gives the descriptions for each

    You could also use a table, e.g. if the lower bounds were in J2:J9 and the descriptions in K2:K9 then the formula would be

    =LOOKUP(DATEDIF(A2,D$1,"y"),J$2:K$9)

    This second approach is recommended, especially if you might want to change the range sizes or definitions. You can then do that without altering the formula.

  7. #7
    Registered User
    Join Date
    10-26-2008
    Location
    dublin
    Posts
    10

    Re: Applying date range

    This is great, Im so glad I encountered this problem as between all the suggestions I already have multiple other uses I can apply this to

    Thanks again!!

+ 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