web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Calculate an age based...
Power Apps
Answered

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

(0) ShareShare
ReportReport
Posted on 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?

Categories:
I have the same question (0)
  • ManishSolanki Profile Picture
    15,091 Super User 2025 Season 2 on at

    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

  • WarrenBelz Profile Picture
    153,117 Most Valuable Professional on at

    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

  • StuC Profile Picture
    50 on at

    @WarrenBelz 

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

  • ManishSolanki Profile Picture
    15,091 Super User 2025 Season 2 on at

    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

  • WarrenBelz Profile Picture
    153,117 Most Valuable Professional on at

    @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 ?

  • Verified answer
    WarrenBelz Profile Picture
    153,117 Most Valuable Professional on at

    @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

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard