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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Calculating number of ...
Power Apps
Answered

Calculating number of days based on time of year.

(0) ShareShare
ReportReport
Posted on by 61

Hi everyone. I'm building a leave request system in Powerapps for Teams. The employees leave allowance gets reset every year. The year is based on the employees birth month i.e. if an employee's birthday is the 10th of May, on the 1st of May their holiday allowance is reset.

I've created a form to capture the users leave allowance, and how many (if any) days have been taken so far this year, and the users birth month (using a combo box and the items set as Calendar.MonthsLong()).

Within the OnVisible property of the Employee Dashboard screen I've entered the following code to create a variable called varCalcDaysTaken:

Set(varBirthMonth, DateValue("1 " & LookUp('Leave Allowances', 'Employee Name' = User().FullName).MyBirthMonth & " " & Year(Now())));
Set(varBirthMonthDay, Day(varBirthMonth));
// Calculate number of days taken if it's after the 1st day of the user's birth Month, the type of leave is Annual Leave and the status is Accepted
Set(varCalcDaysTaken, 
 If(
 Day(Now()) = varBirthMonthDay,
 0,
 Sum(
 Filter(WaSS_LeaveRequests, 
 Day('Start Date') > varBirthMonthDay, 
 Name = User().FullName, 
 'Type of leave' = (LeaveTypeChoice).'Annual Leave',
 RequestStatus = (StatusChoice).Accepted || RequestStatus = (StatusChoice).New
 ),
 'Number of Days')
 )
);

 

Then to output the balance I've entered the following code into the Text property of a label called lbl_Allocation:

If(Text(LeaveType.Selected.Value) = "Annual Leave",
 LookUp('Leave Allowances','Employee Name'=User().FullName).Allowance 
 - LookUp('Leave Allowances','Employee Name'=User().FullName).'Days Taken So Far'
 - varCalcDaysTaken
 - NumberOfDays.Text,
LookUp('Leave Allowances','Employee Name'=User().FullName).Allowance 
- LookUp('Leave Allowances','Employee Name'=User().FullName).'Days Taken So Far'
- varCalcDaysTaken
)

 This ALMOST works, I'm struggling with reset on the first day of the users birth month.


I've been using Copilot to help me and this is what it offered:

Set(varBirthDate, DateValue("1 " & LookUp('Leave Allowances', 'Employee Name' = User().FullName).MyBirthMonth & " " & Year(Now())));
Set(varBirthMonth, Month(varBirthDate));
Set(varBirthMonthDay, Day(varBirthDate));
Set(
 varCalcDaysTaken,
 If(
 Now() < DateAdd(varBirthDate, 1),
 Sum(
 Filter(
 WaSS_LeaveRequests,
 'Start Date' >= varBirthDate,
 'Start Date' < DateAdd(varBirthDate, 1),
 Name = User().FullName,
 'Type of leave' = (LeaveTypeChoice).'Annual Leave',
 RequestStatus = (StatusChoice).Accepted || RequestStatus = (StatusChoice).New
 ),
 'Number of Days'
 ),
 0
 )
);

This very close but still doesn't quite do it. After the 'reset' it still takes into account holidays from the previous year.

Can anyone out there help me with this? My brain is melting! 

Categories:
I have the same question (0)
  • mmbr1606 Profile Picture
    14,629 Super User 2026 Season 1 on at

    hey @WayneSS 

     

    can you try this:

    Set(varBirthDate, 
     DateValue(
     "1 " & LookUp('Leave Allowances', 'Employee Name' = User().FullName).MyBirthMonth & 
     " " & If(
     Month(Now()) < Month(DateValue("1 " & LookUp('Leave Allowances', 'Employee Name' = User().FullName).MyBirthMonth & " " & Year(Now()))),
     Year(Now()) - 1,
     Year(Now())
     )
     )
    );
    
    
    Set(varCalcDaysTaken,
     If(
     Now() < varBirthDate,
     0, // If it's before the cycle start, no days should be taken
     Sum(
     Filter(
     WaSS_LeaveRequests,
     'Start Date' >= varBirthDate,
     'Start Date' <= Now(),
     Name = User().FullName,
     'Type of leave' = (LeaveTypeChoice).'Annual Leave',
     RequestStatus = (StatusChoice).Accepted || RequestStatus = (StatusChoice).New
     ),
     'Number of Days'
     )
     )
    );
    

    and this for the label 

    If(
     Text(LeaveType.Selected.Value) = "Annual Leave",
     LookUp('Leave Allowances', 'Employee Name' = User().FullName).Allowance - 
     LookUp('Leave Allowances', 'Employee Name' = User().FullName).'Days Taken So Far' -
     varCalcDaysTaken -
     Value(NumberOfDays.Text), // Make sure to convert text input to number if necessary
     LookUp('Leave Allowances', 'Employee Name' = User().FullName).Allowance - 
     LookUp('Leave Allowances', 'Employee Name' = User().FullName).'Days Taken So Far' -
     varCalcDaysTaken
    )
    

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • WayneSS Profile Picture
    61 on at

    Sorry for late response to this, I originally thought it was working. However, it's still not quite right.

    Maybe if I explain it better:
    If a users birthday is 1st July, only take into consideration the days of leave that occur between 1st July 2023 and 1st July 2024.
    At the moment it only takes into account dates after 1st July 2023 and dates before Now. I have removed the line of code from the Filter that states 'Start Date' <= Now() but then it includes any dates after 1st July 2024.

  • Verified answer
    WayneSS Profile Picture
    61 on at

    I've finally cracked it!

    Here's the code to create the calculation:

    Set(varBirthDateStart, 
     DateValue(
     "1 " & LookUp('Leave Allowances', 'Employee Name' = User().FullName).MyBirthMonth & 
     " " & Year(Now()) - 1
     )
    );
    Set(varBirthDate, 
     DateValue(
     "1 " & LookUp('Leave Allowances', 'Employee Name' = User().FullName).MyBirthMonth & 
     " " & Year(Now())
     )
    );
    Set(varBirthDateEnd,
     If(Now() >= varBirthDate,
     DateValue(
     "1 " & LookUp('Leave Allowances', 'Employee Name' = User().FullName).MyBirthMonth & 
     " " & Year(Now()) + 1
     )
     )
    );
    Set(varCalcDaysTaken,
     If(
     Now() < varBirthDate,
     Sum(
     Filter(
     WaSS_LeaveRequests,
     'Start Date' >= varBirthDateStart,
     'Start Date' < varBirthDate,
     Name = User().FullName,
     Reason = "Annual Leave",
     Request_Status = "Accepted" || Request_Status = "New"
     ),
     'Number of Days'
     ),
     Now() >= varBirthDate,
     Sum(
     Filter(
     WaSS_LeaveRequests,
     'Start Date' >= varBirthDate,
     'Start Date' < varBirthDateEnd,
     Name = User().FullName,
     Reason = "Annual Leave",
     Request_Status = "Accepted" || Request_Status = "New"
     ),
     'Number of Days'
     )
     )
    );

     

    And here's the code to use in the Text property of the label that shows the balance:

    If(TypeOfLeaveInput.Selected.Value = "Annual Leave",
     LookUp('Leave Allowances','Employee Name' = User().FullName).Allowance 
     - LookUp('Leave Allowances','Employee Name'= User().FullName).'Days Taken So Far'
     - varCalcDaysTaken
     - NumberOfDays.Text,
    LookUp('Leave Allowances','Employee Name'=User().FullName).Allowance 
    - LookUp('Leave Allowances','Employee Name'=User().FullName).'Days Taken So Far'
    - varCalcDaysTaken
    )

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 358 Most Valuable Professional

#2
11manish Profile Picture

11manish 214 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 185

Last 30 days Overall leaderboard