cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Shaifu2K
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
Eelman
Super User
Super User

@Shaifu2K 

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
        AddColumns(
                    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                    
        AddColumns(Leave,"LeaveCount", 
            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
        AddColumns(
                    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                    
        AddColumns(Leave,"LeaveCount", 
            Switch(WeekD, 
                7, 0.5,
                1, 0,
                1
            )
        )
 ),
LeaveCount
)

 

Which looks like this:

LeaveCount.jpg

 

 

View solution in original post

2 REPLIES 2
VijayTailor
Resident Rockstar
Resident Rockstar

Hi @Shaifu2K ,

you can check the below-highlighted approach for calculation.

VijayTailor_0-1613937278584.png

Hope this will help you somehow

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,

Eelman
Super User
Super User

@Shaifu2K 

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
        AddColumns(
                    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                    
        AddColumns(Leave,"LeaveCount", 
            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
        AddColumns(
                    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                    
        AddColumns(Leave,"LeaveCount", 
            Switch(WeekD, 
                7, 0.5,
                1, 0,
                1
            )
        )
 ),
LeaveCount
)

 

Which looks like this:

LeaveCount.jpg

 

 

View solution in original post

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

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Top Kudoed Authors
Users online (58,239)