cancel
Showing results for
Did you mean: Regular Visitor

## Counting Saturdays As Half-Day

Hi! I'm building my first Power App which is a leave request app.

Currently, the app accepts a start date and end date of the leave and I calculate the days based on the user inputs. The requirements needed are that Sundays and holidays will be excluded in the calculation and that Saturdays will be counted as half-day (0.5). I already did the exclusion of holidays but I can't figure out how to exclude Sundays and at the same time count Saturdays as half-days.

Can anyone help? Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions  Super User

Another option could be to use the Weekday() function in a dynamic way.

Assume you have two DatePickers, ie dpStart and dpEnd. If you add the following code to a gallery you can see the Leave Count for dates between the 2 selected dates (inclusive):

``````With(
{
Leave:
// Table of Dates from Start to End, Inclusive
Sequence(DateDiff(dpStart.SelectedDate, dpEnd.SelectedDate,Days)+1,
Date(Year(dpStart.SelectedDate),
Month(dpStart.SelectedDate),
Day(dpStart.SelectedDate)), 1000*60*60*24) As LeavePeriod,

// Converts date to a Weekday value
"WeekD",  Weekday(Date(
Year(LeavePeriod.Value),
Month(LeavePeriod.Value),
Day(LeavePeriod.Value)))
)
},
// Switch uses, 7 = Saturday, 1 = Sunday
Switch(WeekD,
7, 0.5,
1, 0,
1
)
)
)``````

If you just want a label to show the count of days you can wrap the above in Sum(), like this:

``````Sum(
With(
{
Leave:
// Table of Dates from Start to End, Inclusive
Sequence(DateDiff(dpStart.SelectedDate, dpEnd.SelectedDate,Days)+1,
Date(Year(dpStart.SelectedDate),
Month(dpStart.SelectedDate),
Day(dpStart.SelectedDate)), 1000*60*60*24) As LeavePeriod,

// Converts date to a Weekday value
"WeekD",  Weekday(Date(
Year(LeavePeriod.Value),
Month(LeavePeriod.Value),
Day(LeavePeriod.Value)))
)
},
// Switch uses, 7 = Saturday, 1 = Sunday
Switch(WeekD,
7, 0.5,
1, 0,
1
)
)
),
LeaveCount
)``````

Which looks like this: 2 REPLIES 2  Resident Rockstar

Hi @Shaifu2K ,

you can check the below-highlighted approach for calculation. Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."-Vijay

,
Thanks,  Super User

Another option could be to use the Weekday() function in a dynamic way.

Assume you have two DatePickers, ie dpStart and dpEnd. If you add the following code to a gallery you can see the Leave Count for dates between the 2 selected dates (inclusive):

``````With(
{
Leave:
// Table of Dates from Start to End, Inclusive
Sequence(DateDiff(dpStart.SelectedDate, dpEnd.SelectedDate,Days)+1,
Date(Year(dpStart.SelectedDate),
Month(dpStart.SelectedDate),
Day(dpStart.SelectedDate)), 1000*60*60*24) As LeavePeriod,

// Converts date to a Weekday value
"WeekD",  Weekday(Date(
Year(LeavePeriod.Value),
Month(LeavePeriod.Value),
Day(LeavePeriod.Value)))
)
},
// Switch uses, 7 = Saturday, 1 = Sunday
Switch(WeekD,
7, 0.5,
1, 0,
1
)
)
)``````

If you just want a label to show the count of days you can wrap the above in Sum(), like this:

``````Sum(
With(
{
Leave:
// Table of Dates from Start to End, Inclusive
Sequence(DateDiff(dpStart.SelectedDate, dpEnd.SelectedDate,Days)+1,
Date(Year(dpStart.SelectedDate),
Month(dpStart.SelectedDate),
Day(dpStart.SelectedDate)), 1000*60*60*24) As LeavePeriod,

// Converts date to a Weekday value
"WeekD",  Weekday(Date(
Year(LeavePeriod.Value),
Month(LeavePeriod.Value),
Day(LeavePeriod.Value)))
)
},
// Switch uses, 7 = Saturday, 1 = Sunday
Switch(WeekD,
7, 0.5,
1, 0,
1
)
)
),
LeaveCount
)``````

Which looks like this:     