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 / Time off leave applica...
Power Apps
Answered

Time off leave application

(0) ShareShare
ReportReport
Posted on by

I am working on a leave application, and I am stuck at a function or how to implement the function.

I have a Leave request screen that has a Start date (user selects start of a leave) and End date (user selects end of a leave).

I would like to be able to:-

1) add an hours off field such that a user can be able to request hours off if they select same day leave request.

2) If the cumulative hours off on different days reach 7 hours, a day is deducted off the total leave balance .

 

Attached see the representation of the app and the share point lists.

 

Thanks in advance.

question2.PNG
question3.PNG
Question.PNG
Categories:
I have the same question (0)
  • Verified answer
    AARON_C Profile Picture
    2,235 Most Valuable Professional on at

    Hi @TYNAI,

     

    I've made a test of this that updates the amount of available leave hours of staff instantly. How I have done this.

     

    Created two tables: Staff and StaffLeave

    AARON_C_0-1699670076598.pngAARON_C_1-1699670181546.png

     

    This is the small test I have made.

    AARON_C_3-1699670367411.png

     

    --------------------------------------------------------------------------

    The code:

     

    For the buttons OnSelect property, I have: 

    Set(varLeaveType, "Annual"); // Change the leave tpye for each button

     

    For the Text Input (Hours Off) in the Default property:

    DateDiff(DatePicker1.SelectedDate, DatePicker2.SelectedDate) * 8 
    \\ I am assuming 8 hours is the standand amount of hours in a working day

     The Visible property is still the same

     

    For the Submit button, the OnSelect property:

    Patch(StaffLeaves, 
     Defaults(StaffLeaves), 
     {
     StaffName: LookUp(Staff, Name = User().FullName),
     LeaveType: varLeaveType,
     DateFrom: DatePicker1.SelectedDate,
     DateTo: DatePicker2.SelectedDate,
     LeaveTakenHours: Value(TextInput1.Text)
     }
    );
    
    With(
     {
     staffDetails: 
     {
     staffName: LookUp(Staff, Name = User().FullName),
     staffAL: LookUp(Staff, Name = User().FullName).AnnualLeave,
     staffSL: LookUp(Staff, Name = User().FullName).SickLeave,
     staffML: LookUp(Staff, Name = User().FullName).MaternityLeave
     }
     
     },
    
     Switch(varLeaveType,
     "Annual",
     Patch(Staff, 
     staffDetails.staffName,
     {
     AnnualLeave: staffDetails.staffAL - Value(TextInput1.Text)
     }
     ),
     "Sick",
     Patch(Staff, 
     staffDetails.staffName,
     {
     SickLeave: staffDetails.staffSL - Value(TextInput1.Text)
     }
     ),
     "Maternity",
     Patch(Staff, 
     staffDetails.staffName,
     {
     MaternityLeave: staffDetails.staffML - Value(TextInput1.Text)
     }
     )
     )
    )

     

    Let me know if you need any more help with this.

     

    Please tick Accept as solution if the answer is useful.

    Thanks,

    @AARON_C 

  • TYNAI Profile Picture
    on at

    The period is measured for every year. there is annual leave which is 21days in a year, sick leave which is 28 days in a year, compassionate leave which is 7 days in a year, once a year ends They are rested and a user is only allowed to carry over 15 days to the next year

  • TYNAI Profile Picture
    on at

    @AARON_C this was my train of thought but i could not figure out how to apply it. 

    But for your question:  If you take 3 hours off on the 11/10/23, then your next time you take a full day off on the 1/31/24. What happens then? the 3 hours off will remain Hanging somewhere, waiting for when 4 hours is added in the future. but i would like to explore your suggestion. how can this be implemented?

  • AARON_C Profile Picture
    2,235 Most Valuable Professional on at

    @TYNAI 

     

    Shouldn't you record the leave amount by the amount of hours a person has? If you take 3 hours off on the 11/10/23, then your next time you take a full day off on the 1/31/24. What happens then? How is a period measured?

  • TYNAI Profile Picture
    on at

    hi @Jayden_Pillay16 , let me try this and let you know if it works in a few minutes. Thanks 

  • TYNAI Profile Picture
    on at

    Hi @AARON_C   , Thanks, for the first answer it works! for the second question :- If you want to take time off, you first choose the start and end dates. Then, you enter the number of hours you want to take off. If you take off 7 cumulative hours within a period, the system will recognize it as a day off and deduct 1 day from your total leave days. The system will then reset and start counting again. Here is a step-by-step example: On Friday, 11/10/23, you want to take 3 hours off. You choose 11/10/23 as the start date and 11/10/23 as the end date. You select 3 hours in the "Hours off" text box. On Monday, 11/13/23, you want to take 4 hours off. You choose 11/13/23 as the start date and 11/13/23 as the end date. You select 4 hours in the "Hours off" text box. Now, you have taken a total of 7 hours off within a period. The system will recognize this as a day off and deduct 1 day from your total leave days. The system will then reset and start counting again. Maybe this is more clear

  • AARON_C Profile Picture
    2,235 Most Valuable Professional on at

    Hi @TYNAI,

     

    For your first question set the Visible property of the Hours Off label and text input to: 

     

     

    DatePicker1.SelectedDate = DatePicker2.SelectedDate

     

     

     

    And could you please clarify number 2. If I take 2 days off, that is more than 7 hours. I get a day off for free?

     

    Please tick Accept as solution if the answer is useful.

    Thanks,

    @AARON_C 

     

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
Kalathiya Profile Picture

Kalathiya 400

#2
WarrenBelz Profile Picture

WarrenBelz 348 Most Valuable Professional

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 315 Super User 2025 Season 2

Last 30 days Overall leaderboard