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 / Calculating Time corre...
Power Apps
Unanswered

Calculating Time correctly in PowerApps for a Timesheet scenario

(0) ShareShare
ReportReport
Posted on by 34

I have previously created a topic about this but no one got back to me after the first reply so therefore posting again and hoping someone can help me.  Basically I am creating an app for employees to enter their time into which once the week is collected that data is sent to a SharePoint list.  We want their hours calculated based on their start and finish time.  When an employee enters their hours their lunch break (30mins) is taken off their hours and their break (15mins) is added on to be correct, however some employees work on several projects in one day.  Once they submit time for a date it is added to a collection 'colTimeEntryWeek' My problem is once an employee has already submitted time for a day when they try to submit time spent on another project for the same date I don't want their break and lunch break hours to be added on / taken off their hours again as they already will have had that adjusted by their first entry for that day.

 

My initial formula to get their hours with break and lunch break taken into account is:

 

If(
 Or(cbxProjectSTE.Selected.Value = "Day Off", cbxProjectSTE.Selected.Value = "Off Sick"), "0",
 Or(cbxProjectSTE.Selected.Value = "Holiday", cbxProjectSTE.Selected.Value = "Travel Day"), "9.5",

With({StartFinishDiff:
 DateDiff(
 TimeValue(drpStartTimeSTE1.Selected.Value & ":" & drpStartTimeSTE2.Selected.Value),
 TimeValue(drpFinishTimeSTE1.Selected.Value & ":" & drpFinishTimeSTE2.Selected.Value) - TimeValue(txtLunchBreakSTE) + TimeValue(txtBreakSTE), Minutes)},
With({MinDiff: Mod(StartFinishDiff, 60)},
With({MinAdjustment: If(Mod(MinDiff,15)>7, 15-Mod(MinDiff, 15), -Mod(MinDiff, 15))},
((StartFinishDiff - MinDiff)/60 + Text( (MinDiff + MinAdjustment)/15 * .25,"[$-en-US].0#"))))))

 

Now trying to figure out how to write formula so that if they are submitting more time for this date it checks my collection to see if there is already time on this date and if there is then don't adjust hours by taking away their lunch break time and adding their break time.  If there isn't any time on this date then do the calculation.  I am trying the below:

 

If(
 Or(cbxProjectSTE.Selected.Value = "Day Off", cbxProjectSTE.Selected.Value = "Off Sick"), "0",
 Or(cbxProjectSTE.Selected.Value = "Holiday", cbxProjectSTE.Selected.Value = "Travel Day"), "9.5",

 If(
 IsEmpty(
 LookUp(colTimeEntryWeek, Date_ = datDateSTE.SelectedDate)),

With({StartFinishDiff:
 DateDiff(
 TimeValue(drpStartTimeSTE1.Selected.Value & ":" & drpStartTimeSTE2.Selected.Value),
 TimeValue(drpFinishTimeSTE1.Selected.Value & ":" & drpFinishTimeSTE2.Selected.Value), TimeUnit.Minutes)},
 
With({StartFinishDiff:
 DateDiff(
 TimeValue(drpStartTimeSTE1.Selected.Value & ":" & drpStartTimeSTE2.Selected.Value),
 TimeValue(drpFinishTimeSTE1.Selected.Value & ":" & drpFinishTimeSTE2.Selected.Value) - TimeValue(txtLunchBreakSTE) + TimeValue(txtBreakSTE), TimeUnit.Minutes)},
With({MinDiff: Mod(StartFinishDiff, 60)},
With({MinAdjustment: If(Mod(MinDiff,15)>7, 15-Mod(MinDiff, 15), -Mod(MinDiff, 15))},
((StartFinishDiff - MinDiff)/60 + Text( (MinDiff + MinAdjustment)/15 * .25,"[$-en-US].0#"))))))))

 

It's not quite right as it works fine for first submission hours are calculated correctly but if I try to enter more information on this date the hours are just blank.

Please help me find where I have went wrong or a better way to do it.  I am struggling and desperate for a resolution.  If anyone needs more info please let me know.

powerappssampleimageofhoursissue.PNG
Categories:

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
11manish Profile Picture

11manish 402 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 296 Most Valuable Professional

Last 30 days Overall leaderboard