cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
spow
Frequent Visitor

Leave Template - Include half day option

I have modified the Leave Template for a team within my company and this is working successfully. However, they require the ability to be able to book a half day's leave. I have looked at several posts within here asking the same question and have tried some of the recommended solutions but absolutely none of them work! This is the most recent one I tried but see that the person that raised it never got any further response when it didn't work for them either:

 

https://powerusers.microsoft.com/t5/Building-Power-Apps/My-leave-request-template-Balance-Add-Select...

 

I understand that the calculation will need to be added under the start date picker but just cannot get anything to work.

 

I would really appreciate some guidance as I've spent hours on trying to find a solution.

 

Thank you in anticipation.

16 REPLIES 16
jbrit2020
Responsive Resident
Responsive Resident

Can you share a bit more about your app? how you store the leave balance and or perhaps a screenshot of the app itself?

 

Seems like a quick checkbox + submit button fix (then again...perhaps not)

spow
Frequent Visitor

I've used the Leave Template in Powerapps which has pre-defined formulas (Leave1 attachment). I have successfully tweaked all the formulas and have it attached to a Sharepoint list rather than Excel which is what the template does.

 

The formula for the days sits behind the start leave date picker and is as follows:

 

If(LeaveStartDatePicker.SelectedDate <= LeaveEndDatePicker.SelectedDate,
Set(_inclusiveTotalDaysRequested, DateDiff(LeaveStartDatePicker.SelectedDate,LeaveEndDatePicker.SelectedDate, Days) + 1),

It then goes on to set variables for full weeks and days etc.

 

The link that I mentioned in my first post suggests full day/am/pm checkboxes and the attached formula (Leave2) but I cannot get it to work at all.

 

I've also tried the formula in Leave3 attachment which was another post I read but no joy!

Does that explain it?

v-bofeng-msft
Community Support
Community Support

Hi @spow :

Do you want to add an "half day" option base on the leave request template?

If so,please try this solution:

1\Add two Radio controls(Radio1ForLeaveStartDatePicker/Radio2ForLeaveEndDatePicker) into NewRequestScreen screen:

Items

["AM","PM"]

 OnChange

Select(LeaveStartDatePicker)

Default

"AM"

2\Set LeaveStartDatePicker's OnSelelct property to

 

//**** CALCULATION USED TO DETERMINE TOTAL WORK DAYS REQUESTED ****
If(LeaveStartDatePicker.SelectedDate <= LeaveEndDatePicker.SelectedDate,
    Set(_inclusiveTotalDaysRequested, DateDiff(LeaveStartDatePicker.SelectedDate, LeaveEndDatePicker.SelectedDate, Days) + 1);
    Set(_numFullWeeks, RoundDown(_inclusiveTotalDaysRequested / 7, 0));
    Set(_numFullDaysPartialWeek, _inclusiveTotalDaysRequested - _numFullWeeks * 7);
    Concurrent(Set(_startWeekday, Weekday(LeaveStartDatePicker.SelectedDate)), Set(_endWeekday, Weekday(LeaveEndDatePicker.SelectedDate)));
    //calculates the number of business days in the partial week left over after whole weeks are subtracted out of total days requested
    If(_numFullDaysPartialWeek = 6,
        If(_startWeekday <= 2, Set(_numPartialWeekdays, 5), Set(_numPartialWeekdays, 4)
        ),
      _numFullDaysPartialWeek = 5,
        If(_startWeekday = 2, Set(_numPartialWeekdays, 5), _startWeekday = 1 || _startWeekday = 3 || _startWeekday = 4, Set(_numPartialWeekdays, 4), Set(_numPartialWeekdays, 3)
        ),
      _numFullDaysPartialWeek = 4,
        If(_startWeekday = 2 || _startWeekday = 3, Set(_numPartialWeekdays, 4), _startWeekday = 1 || _startWeekday = 4, Set(_numPartialWeekdays, 3), Set(_numPartialWeekdays, 2)
        ),
      _numFullDaysPartialWeek = 3,
        If(_startWeekday = 6 || _startWeekday = 7, Set(_numPartialWeekdays, 1), _startWeekday = 1 || _startWeekday = 5, Set(_numPartialWeekdays, 2), Set(_numPartialWeekdays, 3)
        ),
      _numFullDaysPartialWeek = 2,
        If(_startWeekday = 7, Set(_numPartialWeekdays, 0), _startWeekday = 1 || _startWeekday = 6, Set(_numPartialWeekdays, 1), Set(_numPartialWeekdays, 2)),
      _numFullDaysPartialWeek = 1,
        If(_startWeekday = 1 || _startWeekday = 7, Set(_numPartialWeekdays, 0), Set(_numPartialWeekdays, 1)
        ),
      _numFullDaysPartialWeek = 0, Set(_numPartialWeekdays, 0)
    );
If(Radio1ForLeaveStartDatePicker.SelectedText.Value="PM" &&_startWeekday<>1&&_startWeekday<>7, Set(_numPartialWeekdays, _numPartialWeekdays-0.5));
If(Radio2ForLeaveEndDatePicker.SelectedText.Value="AM" &&_startWeekday<>1&&_startWeekday<>7, Set(_numPartialWeekdays, _numPartialWeekdays-0.5));
      Set(_workDaysInRequest, _numFullWeeks * 5 + _numPartialWeekdays); 
      Set(_holidaysInRequest, CountIf(HolidaysCollection, StartDate >= LeaveStartDatePicker.SelectedDate, StartDate <= LeaveEndDatePicker.SelectedDate));
      Set(_requestedDays, _workDaysInRequest - _holidaysInRequest)
)
The Result:
41.gif
Best Regards,
Bof

Hi, 

How to exclude sunday alone from above code. In this code it excluded weekend days(Saturday and Sunday) but I want to set Saturday as a business day. 

Hi, 

When approved
Negative data 1 day, not 0.5 days.

Help me please.

spow
Frequent Visitor

Hi - I'm not entirely sure as I am using the code from the template - might be an idea to do a separate post for that?

Hi 

 

Apologies for late response as I have only just had a chance to try this and I really appreciate your time in responding,

 

I went through your guidance above but it's still not working, it's does not seem to be registering the AM and PM and is still taking the dates selected as whole days - see attachment HalfDay1.  And consequently this is not pulling through correctly on the request details - see attachment HalfDay2.

 

Am I missing something? 

 

Just to confirm both the On Change for both radio controls is set to LeaveStartDatePicker?

 

Very frustrated with this and if I can't get this to work, I will have to look at doing my own and waste weeks of work. Defeats the object of having a "quick" template!

 

Thank you in anticipation.

ofmano89
Frequent Visitor

Hi 

from picture HalfDay1 You can check 

 

OnChange

Select(LeaveStartDatePicker)

spow
Frequent Visitor

Yes - already set at this 

Halfday.PNG

Do both radios need to be set to this?

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (2,426)