web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to get the right w...
Power Apps
Unanswered

How to get the right working hours per day based on a date range ina TimeOff scenario

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi team,

 

I have a TimeOff application that add requests in date range (VacationRequest a SP list), the app allows to enter either 8 or 4 hrs per off day request. An example of the list is below:

 

VacationRequest:

Title              From                      To                            Days       Hrs

Peter            2022-10-05           2022-10-11              5             40

Tony            2022-10-28           2022-10-28              0.5             4

Henry          2022-10-25           2022-10-26              1.5             12

 

Resource Managers will pull a request and either Approve or Reject the request, the approve button generate the DetailedVacation collection and will update the SP TimeOff Calendar with the day and Time approved as follows:

 

Set(selectedItem,ThisItem);
  ClearCollect(
    DetailedVacation ,
    AddColumns(
       FirstN(
         [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41],
         DateDiff(selectedItem.From, selectedItem.To, Days) + 1),
     "Day",  "Day " & (Value + 1),
    "Date",   DateAdd(selectedItem.From, Value, Days),

    "Type",selectedItem.TimeOffType.Value,
    "Hours","8",
    "Person",Title));
// remove weekend and holiday from employee calendar
RemoveIf(DetailedVacation ,Weekday(Date) = 1 Or Weekday(Date) = 7 Or !IsBlank(LookUp(HolidayCalendar,Text(holWorkDate,DateTimeFormat.ShortDate) = Text(Date,DateTimeFormat.ShortDate) 
)));

 

Correct generated collection for Peter's request: 

DetailedVacation

Person          From                      Hours

Peter            2022-10-05              8

Peter            2022-10-06              8

Peter            2022-10-07              8

Peter            2022-10-10              8

Peter            2022-10-11              8

 

Wrong generated collection for Tony's request, it should say 4 hrs: 

DetailedVacation

Person          From                      Hours

Tony             2022-10-28            8

 

Wrong generated collection for Henry's request, it should say 8 and 4 hrs: 

DetailedVacation

Person          From                      Hours

Henry           2022-10-25              8

Henry           2022-10-26              8

 

I would appreciate you can help me to correct or re-write above code.

Categories:
I have the same question (0)

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 392 Most Valuable Professional

#2
11manish Profile Picture

11manish 181 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 112 Super User 2026 Season 2

Last 30 days Overall leaderboard