Skip to main content

Notifications

Community site session details

Community site session details

Session Id : UOmTjoylAMcRbtgPuQ0qOS
Power Apps - Building Power Apps
Answered

Calculate an age based on DOB but also on the start date of an event

Like (0) ShareShare
ReportReport
Posted on 23 Apr 2023 19:21:36 by 50

Hi have two sharepoint lists.  Students and Group.  Students age is calculated on Date of birth and also on the start date of the event.

If(
 IsBlank(StudentDOB.SelectedDate),
 ThisItem.StudentAge,
 Round(
 DateDiff(
 StudentDOB.SelectedDate,
 LookUp(
 Group,
 Title = GroupTitleComboBox1.Selected.Title,
 StartDate
 )
 ) / 365,
 0
 )
)

It works unless the date is passed the startdate and then it adds 1 year.  any solutions out there?

  • Verified answer
    WarrenBelz Profile Picture
    146,702 Most Valuable Professional on 23 Apr 2023 at 22:22:37
    Re: Calculate an age based on DOB but also on the start date of an event

    @StuC 

    You are correct (I tested it), you need

    If(
     IsBlank(StudentDOB.SelectedDate),
     ThisItem.StudentAge,
     RoundDown(
     DateDiff(
     StudentDOB.SelectedDate,
     LookUp(
     Group,
     Title = GroupTitleComboBox1.Selected.Title
     ).StartDate,
     TimeUnit.Days
     )/365.25,
     0
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

     

  • WarrenBelz Profile Picture
    146,702 Most Valuable Professional on 23 Apr 2023 at 20:44:02
    Re: Calculate an age based on DOB but also on the start date of an event

    @StuC ,

    Then the code I posted should work - it rounds down the date period to whole years - I assume you want the actual age so 12 years and 1 day equals 12 years ?

  • ManishSolanki Profile Picture
    15,085 Super User 2025 Season 1 on 23 Apr 2023 at 20:39:28
    Re: Calculate an age based on DOB but also on the start date of an event

    Hi @WarrenBelz 

     

    Thanks for your suggestion but it will not give the correct result if date & month of Start event is less that the DOB. For e.g., if DOB is 1-May-2020 and Event Date is 1-Apr-2023 then it gives 23 years but the actual result should be 22 years. The result should be 23 if Event Date goes past or equal to 1-May-2023.

    I have taken care of this rule in the formula which I have shared in my reply.

     

    Thanks

  • StuC Profile Picture
    50 on 23 Apr 2023 at 20:30:06
    Re: Calculate an age based on DOB but also on the start date of an event

    @WarrenBelz 

    Based on StartDate I want to make the student a year older or not.

  • WarrenBelz Profile Picture
    146,702 Most Valuable Professional on 23 Apr 2023 at 20:15:23
    Re: Calculate an age based on DOB but also on the start date of an event

    Hi @StuC ,

    I am not totally clear on your exact rounding requirements, but try this

    If(
     IsBlank(StudentDOB.SelectedDate),
     ThisItem.StudentAge,
     RoundDown(
     DateDiff(
     StudentDOB.SelectedDate,
     LookUp(
     Group,
     Title = GroupTitleComboBox1.Selected.Title
     ).StartDate,
     TimeUnit.Years
     ),
     0
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • ManishSolanki Profile Picture
    15,085 Super User 2025 Season 1 on 23 Apr 2023 at 20:11:27
    Re: Calculate an age based on DOB but also on the start date of an event

    Hi @StuC 

     

    To resolve extra year in DOB, use the below formula, assuming you need age in years only:

     

    If(
    IsBlank(StudentDOB.SelectedDate),
    ThisItem.StudentAge,
    With({varDOB: LookUp(
    Group,
    Title = GroupTitleComboBox1.Selected.Title,
    StartDate
    )},If((Month(StudentDOB.SelectedDate) > Month(varDOB)) Or (Month(StudentDOB.SelectedDate) = Month(varDOB) And Day(StudentDOB.SelectedDate)>=Day(varDOB)) , Year(StudentDOB.SelectedDate) - Year(varDOB),
    Year(StudentDOB.SelectedDate) - Year(varDOB) -1)
    ))

     

    here, idea is to subtract years of both dates if date and month part of start event is more than that of date of birth else it will be one less than the difference between the years of start event and DOB.

     

    Please remember to give a 👍 and accept my solution as it will help others in the future.

     

    Thanks

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,702 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,015 Most Valuable Professional

Leaderboard
Loading started