cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
spow
Helper I
Helper I

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.

20 REPLIES 20
jbrit2020
Continued Contributor
Continued Contributor

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)

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.

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)

Yes - already set at this 

Halfday.PNG

Do both radios need to be set to this?

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,374)