+ Reply to Thread
Results 1 to 4 of 4

Calculate Age then Average Based on Condition

  1. #1
    Registered User
    Join Date
    11-16-2009
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Calculate Age then Average Based on Condition

    I have a spreadsheet where I am trying to return the average age of a patient seen at a particular office. I need to calculate their age by subtracting the DateSeen (Column A) by their DOB (Column C) and then return the results conditionally based on whether they are seen at office 0 or office 1 (Column B). I can use the embed subtraction into an AVERAGE function, but when I attempt to put it into an AVERAGEIF function, it will not result. Any help would be appreciated.

    DateSeen Office DOB ***
    8/15/12 0 9/16/39 Male
    8/22/12 0 4/20/28 Male
    8/22/12 0 3/4/22 Female
    9/5/12 1 6/7/26 Male
    9/19/12 0 8/5/31 Female
    12/19/12 1 5/24/31 Male
    1/9/13 1 4/8/29 Male
    1/16/13 0 2/1/46 Male

  2. #2
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Calculate Age then Average Based on Condition

    Why don't you include an age column then you can use that for the average calculation.

    Data Range
    A
    B
    C
    D
    E
    F
    G
    H
    1
    Date Seen
    Office
    DOB
    Gender
    Age
    ------
    Office
    AVG
    2
    8/15/2012
    0
    9/16/1939
    Male
    72
    0
    79
    3
    8/22/2012
    0
    4/20/1928
    Male
    84
    1
    83
    4
    8/22/2012
    0
    3/4/1922
    Female
    90
    5
    9/5/2012
    1
    6/7/1926
    Male
    86
    6
    9/19/2012
    0
    8/5/1931
    Female
    81
    7
    12/19/2012
    1
    5/24/1931
    Male
    81
    8
    1/9/2013
    1
    4/8/1929
    Male
    83
    9
    1/16/2013
    0
    2/1/1946
    Male
    66


    This formula entered in E2 and copied down:

    =DATEDIF(C2,A2,"Y")

    For the average, this formula entered in H2 and copied down:

    =ROUND(AVERAGEIF(B$2:B$9,G2,E$2:E$9),0)
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  3. #3
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Calculate Age then Average Based on Condition

    If you would rather not have an age column...

    Data Range
    A
    B
    C
    D
    E
    F
    G
    1
    Date Seen
    Office
    DOB
    Gender
    ------
    Office
    AVG
    2
    8/15/2012
    0
    9/16/1939
    Male
    0
    79
    3
    8/22/2012
    0
    4/20/1928
    Male
    1
    83
    4
    8/22/2012
    0
    3/4/1922
    Female
    5
    9/5/2012
    1
    6/7/1926
    Male
    6
    9/19/2012
    0
    8/5/1931
    Female
    7
    12/19/2012
    1
    5/24/1931
    Male
    8
    1/9/2013
    1
    4/8/1929
    Male
    9
    1/16/2013
    0
    2/1/1946
    Male


    This array formula** entered in G2 and copied down:

    =ROUND(AVERAGE(IF(B$2:B$9=F2,DATEDIF(C$2:C$9,A$2:A$9,"Y"))),0)

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.

  4. #4
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,408

    Re: Calculate Age then Average Based on Condition

    In the attached file I've used column E to give you the age in years (and fractions of a year) using this formula in E2:

    =IF(A2="","",(A2-C2)/365.25)

    (this is approximately right), then in the summary table this formula in I2 can give you the average for Males in Office 0:

    =IFERROR(AVERAGEIFS($E:$E,$D:$D,I$1,$B:$B,$H2),"")

    which can be copied into J2 and down, and this formula can give you the overall average for each office in K2, copied down:

    =IFERROR(AVERAGEIFS($E:$E,$B:$B,$H2),"")

    Hope this helps.

    Pete
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 07-07-2014, 04:31 PM
  2. calculate average of counters with a condition (date)
    By Marouenetrab in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-29-2012, 12:44 PM
  3. UDF to calculate average according to condition, ignoring blanks
    By dmitry in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-14-2011, 05:51 PM
  4. Replies: 2
    Last Post: 10-08-2008, 08:39 AM
  5. [SOLVED] formula to calculate the average of a range basing on condition
    By Bob Phillips in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 09-06-2005, 10:05 AM
  6. [SOLVED] formula to calculate the average of a range basing on condition
    By Krishna Mohan in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 AM
  7. [SOLVED] formula to calculate the average of a range basing on condition
    By Krishna Mohan in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM

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