Home

Count full hours that meet a criteria?

%3CLINGO-SUB%20id%3D%22lingo-sub-614084%22%20slang%3D%22en-US%22%3ECount%20full%20hours%20that%20meet%20a%20criteria%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-614084%22%20slang%3D%22en-US%22%3E%3CP%3EHello!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20wish%20to%20enter%20two%20points%20in%20time%20and%20have%20the%20computer%20calculate%20how%20many%20hours%20fit%20the%20met%20criteria.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELet's%20say%20I%20enter%20start%20time%2014%3A00%20and%20end%20time%2022%3A00.%20The%20criteria%20in%20this%20case%20is%20for%20hours%20between%2018%3A00%20and%2022%3A00.%20Here%20I%20want%20the%20computer%20to%20return%204%2C%20as%20in%204%20hours%20fit%20the%20criteria%20(18%3A00-19%3A00%2C%2019%3A00-20%3A00%2C%2020%3A00-21%3A00%2C%2021%3A00-22%3A00).%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20would%20a%20formula%20look%20like%20to%20accomplish%20this%3F%20What%20if%20I%20want%20to%20make%20an%20additional%20criteria%20valid%20for%20specific%20weekdays%2C%20say%20weekends%3F%20What%20if%20the%20times%20pass%20midnight%20and%20end%20on%20another%20weekday%3F%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-614084%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-614121%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20full%20hours%20that%20meet%20a%20criteria%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-614121%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F344668%22%20target%3D%22_blank%22%3E%40jockejocke%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3D(Endtime-Starttime)*24%3C%2FPRE%3E%3CP%3EIt%20is%20unclear%20what%20you%20mean%20by%20%22specific%20workdays%22.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-614125%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20full%20hours%20that%20meet%20a%20criteria%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-614125%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1639%22%20target%3D%22_blank%22%3E%40Detlef%20Lewin%3C%2FA%3E%26nbsp%3BSorry%2C%20but%20this%20is%20not%20so%20simple.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20want%20for%20the%20computer%20to%20compare%20the%20range%20of%20hours%20from%20users%20input%20to%20a%20range%20of%20hours%20set%20in%20the%20criteria.%20As%20in%20the%20example%20above%3A%20User%20inputs%20start%2014%3A00%20and%20end%2022%3A00%2C%20criteria%20is%20valid%20between%2018%3A00%20and%2024%3A00.%20Therefore%204%20hours%20match%20with%20the%20users%20input.%20Computer%20should%20output%204.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWith%20specific%20weekdays%20I%20want%20the%20user%20to%20also%20input%20the%20weekday%20and%20have%20the%20computer%20compare%20the%20weekday%20to%20another%20set%20criteria.%20Say%20criteria%201%20counts%20between%2018%3A00-22%3A00%20mon-fri.%20Criteria%202%20counts%20between%2022%3A00-06%3A00%20mon-fri.%20Criteria%203%20counts%2000%3A00-24%3A00%20sat-sun.%20Should%20the%20user%20input%20start%2019%3A00%20friday%20and%20end%2008%3A00%20saturday%2C%20computer%20should%20output%20criteria%201%3A%203%20hours%2C%20criteria%202%3A%202%20hours%2C%20criteria%203%3A%208%20hours.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20this%20clarifies.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-614777%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20full%20hours%20that%20meet%20a%20criteria%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-614777%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F344668%22%20target%3D%22_blank%22%3E%40jockejocke%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThere%20are%20a%20couple%20of%20approaches%20I%20use%20for%20such%20problems.%3C%2FP%3E%3CP%3EThe%20first%20is%20to%20define%20effective%20start%20and%20finish%20times%20by%3C%2FP%3E%3CP%3E%3D%20MEDIAN(UserStart%2C%20Criterion1Start%2C%20Criterion1End)%3C%2FP%3E%3CP%3E%3D%20MEDIAN(UserFinish%2C%20Criterion1Start%2C%20Criterion1End)%3C%2FP%3E%3CP%3Eand%20then%20the%20qualifying%20hours%20is%3C%2FP%3E%3CP%3E%3D%20End%20-%20Start%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20will%20not%20work%20if%20UserStart%20and%20UserFinish%20are%20arrays%20so%20then%20I%20use%3C%2FP%3E%3CP%3E%3D%20CHOOSE(%201%2B(UserStart%26gt%3BCriterion1Start)%2B(UserStart%26gt%3BCriterion1End)%2C%3C%2FP%3E%3CP%3ECriterion1Start%2C%20UserStart%2C%20Criterion1End)%3C%2FP%3E%3CP%3E%3D%20CHOOSE(%201%2B(UserFinish%26gt%3BCriterion1Start)%2B(UserFinish%26gt%3BCriterion1End)%2C%3C%2FP%3E%3CP%3ECriterion1Start%2C%20UserFinish%2C%20Criterion1End)%3C%2FP%3E%3CP%3Eand%20calculation%20the%20qualifying%20hours%20under%20Criterion1%20as%20an%20array.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ep.s.%20There%20are%20simpler%20formulas%20that%20work%20if%20you%20are%20sure%20that%20the%20user%20hours%20and%20the%20criterion%20hours%20will%20always%20overlap.%26nbsp%3B%20These%20use%20MAX%2FMIN%20or%20IF%20and%20simple%20inequalities%20but%20they%20may%20return%20negative%20times%20if%20the%20conditions%20are%20not%20met.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-618927%22%20slang%3D%22en-US%22%3ERe%3A%20Count%20full%20hours%20that%20meet%20a%20criteria%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-618927%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%26nbsp%3BHello!%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20your%20suggestion%2C%20unfortunately%20I'm%20too%20new%20to%20understand%20how%20to%20apply%20these%20formulas%20into%20a%20single%20cell.%20I'll%20attach%20an%20image%20so%20you%20understand%20what%20I%20mean.%20In%20this%20example%20I%20have%20listed%20times%2C%20criterias%2C%20and%20desired%20output.%20Would%20the%20formulas%20you%20describe%20produce%20this%3F%20%3A)%3C%2FP%3E%3C%2FLINGO-BODY%3E
jockejocke
New Contributor

Hello!

 

I wish to enter two points in time and have the computer calculate how many hours fit the met criteria. 

 

Let's say I enter start time 14:00 and end time 22:00. The criteria in this case is for hours between 18:00 and 22:00. Here I want the computer to return 4, as in 4 hours fit the criteria (18:00-19:00, 19:00-20:00, 20:00-21:00, 21:00-22:00). 

 

What would a formula look like to accomplish this? What if I want to make an additional criteria valid for specific weekdays, say weekends? What if the times pass midnight and end on another weekday? 

4 Replies

@jockejocke 

=(Endtime-Starttime)*24

It is unclear what you mean by "specific workdays".

 

@Detlef Lewin Sorry, but this is not so simple.

 

I want for the computer to compare the range of hours from users input to a range of hours set in the criteria. As in the example above: User inputs start 14:00 and end 22:00, criteria is valid between 18:00 and 24:00. Therefore 4 hours match with the users input. Computer should output 4. 

 

With specific weekdays I want the user to also input the weekday and have the computer compare the weekday to another set criteria. Say criteria 1 counts between 18:00-22:00 mon-fri. Criteria 2 counts between 22:00-06:00 mon-fri. Criteria 3 counts 00:00-24:00 sat-sun. Should the user input start 19:00 friday and end 08:00 saturday, computer should output criteria 1: 3 hours, criteria 2: 2 hours, criteria 3: 8 hours. 

 

Hope this clarifies.  

@jockejocke 

There are a couple of approaches I use for such problems.

The first is to define effective start and finish times by

= MEDIAN(UserStart, Criterion1Start, Criterion1End)

= MEDIAN(UserFinish, Criterion1Start, Criterion1End)

and then the qualifying hours is

= End - Start

 

This will not work if UserStart and UserFinish are arrays so then I use

= CHOOSE( 1+(UserStart>Criterion1Start)+(UserStart>Criterion1End),

Criterion1Start, UserStart, Criterion1End)

= CHOOSE( 1+(UserFinish>Criterion1Start)+(UserFinish>Criterion1End),

Criterion1Start, UserFinish, Criterion1End)

and calculation the qualifying hours under Criterion1 as an array.

 

p.s. There are simpler formulas that work if you are sure that the user hours and the criterion hours will always overlap.  These use MAX/MIN or IF and simple inequalities but they may return negative times if the conditions are not met.

@Peter Bartholomew Hello! 

 

Thank you for your suggestion, unfortunately I'm too new to understand how to apply these formulas into a single cell. I'll attach an image so you understand what I mean. In this example I have listed times, criterias, and desired output. Would the formulas you describe produce this? :)

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
38 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
29 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
13 Replies