Count the number of hours within a certain range on excel - excel

I am wanting to enhance the functionality of my time sheet. I want to calculate if a person's hours falls into a range, and if so, count how many hours. For example:
A user clocks in on their time sheet:
Tuesday: 05:00 - 04:00 i.e. - They worked 23 hours.
From the above time, I want to count how many hours they have worked between the time range 19:30 - 07:30.
Manually calculating this works out at 9.5 hours - or 09:30.
Many thanks.

Formula:
=IF(ClockOut<RangeStart,0,IF(ClockIn>RangeEnd,0,IF(ClockOut<RangeEnd,ClockOut,RangeEnd)-IF(ClockIn>RangeStart,ClockIn,RangeStart)))

This is what is working for me in all the cases I've tested:
Data cells:
A1: Range start | B1: Range end
A2: Clock In       | B2: Clock out
Formula:
=IF(B2<A1,0,IF(A2>B1,0,IF(A2<A1,IF(B2>B1,B1-A1,B2-A1),IF(B2>B1,B1-A2,B2-A2))))
The result is in days, so if you want it in hours, just multiply by 24.
=IF(B2<A1,0,IF(A2>B1,0,IF(A2<A1,IF(B2>B1,B1-A1,B2-A1),IF(B2>B1,B1-A2,B2-A2))))*24
If the times span more than one day, it's crucial for this to work that the cells include the date. In Excel, if you just enter the time, its (fake) date is 00/01/1900, so for the ending times to have the appropriate date, I specified the next day: 01/01/1900. Therefore, if you only have the time, you will have to do this as well.
But if you get a full DateTime from, for example, a database, then you won't have this issue, but you will have to modify the range cells to have the corresponding dates, or modify the clock cells to convert the date back to 00/01/1900, depending on your scenario. Please give some more details if you need help with this.

Related

Pull named range from cell value

I have a spreadsheet used to generate monthly job cards. I need to set it up so it "knows" which month it's on, and on which day number a Monday falls. To this end I have set it up that each day number for every monday this year is listed. Each line on the daily task jobcard is serial numbered from 1 to 28,30, or 31 dependant on the month, so I have set up a formula to check the serial number for the daily task against the day number of each Monday. It works and I have checked this, but the only issue I have is that the formula (=IF(COUNTIF(MARCH23MON,AJ6)>0,$AK$4,$AK$5)) requires me to change the MARCH23MON to match the range for each month up to 31 times every month.
Is there a way to do something like if the date = the date listed in cell a1, then use the value of cell b2 as the range (i.e. MARCH23MON).
See the screenshot here to see how I have begun to set this out. The date for each month is defined by the user in cell C3 when they generate the job cards for the upcoming month, this is then copied into cell AJ2 and formatted to match the dates in AP3:AP14.
I'd like to have the date defined in AJ2 to define the range the formula in AN6:AN36 uses from those listed in AO3:AO14, so that each month is checked against the relevant range of dates.
I had attempted to just use a vlookup then reference the output in this formula =IF(COUNTIF(MARCH23MON,AJ6)>0,$AK$4,$AK$5) as follows =IF(COUNTIF($AL$2,AJ6)>0,$AK$4,$AK$5) which obviously doesn't work. I tried it as ADDRESS($AL$2) but again no worky. Not sure if it is possible.
Foxfire and Burns And Burns mentioned the CHOOSE function in a comment, and that has resolved this for me. Instead of using the list of range names I am now using CHOOSE
to select the dates of each month's Mondays from individual lists. I get the value of AL2 from a VLOOKUP function.

To find number of hours between start date and end date in excel or power bi?

I have a data having two date columns. SHUT HOURS column I calculate after subtracting FEEDON from FEEDOFF date. I need the information for number of shut hours on each day. If I just subtract FEEDON from FEEDOFF, it will give me total number of hours for all days. But I want for each day. Is there any way where I can find number of SHUT HOURS on each day from FEEDOFF and FEEDON date?
The output I want is in the following picture. For example, for first row I want all dates in different cells corresponding to different number of hours. Is there any way to do that?
This is ARRAY (CSE) formula. Press Control+Shift+Enter after pasting the formula.
Formula in G1 is
=ABS(IF(COUNTIFS($A$2:$A$4,"<="&E1+86399/86400,$B$2:$B$4,">="&E1)>0,1,0)*IFERROR(IF(MATCH(E1,INT($A$2:$A$4),0)=MATCH(E1,INT($B$2:$B$4),0),INDEX($B$2:$B$4,MATCH(E1,INT($B$2:$B$4),0),1)-INDEX($A$2:$A$4,MATCH(E1,INT($A$2:$A$4),0),1),""),IFERROR(INDEX($A$2:$A$4,MATCH(E1,INT($A$2:$A$4),0),1)-E1-1,1)*IFERROR(INDEX($B$2:$B$4,MATCH(E1,INT($B$2:$B$4),0),1)-E1,1))*24)
Pasting again being too long to scroll
=ABS(IF(COUNTIFS($A$2:$A$4,"<="&E1+86399/86400,$B$2:$B$4,">="&E1)>0,1,0)*IFERROR(IF(MATCH(E1,INT($A$2:$A$4),0)=MATCH(E1,INT($B$2:$B$4),0),INDEX($B$2:$B$4,MATCH(E1,INT($B$2:$B$4),0),1)-INDEX($A$2:$A$4,MATCH(E1,INT($A$2:$A$4),0),1),""),IFERROR(INDEX($A$2:$A$4,MATCH(E1,INT($A$2:$A$4),0),1)-E1-1,1)*IFERROR(INDEX($B$2:$B$4,MATCH(E1,INT($B$2:$B$4),0),1)-E1,1))*24)
Got help from this link
This will fail if the dates are overlapping as in case of your fourth row is overlapping the first and the third.

Count worktime for current month only

I would like to ask for a bit of help, as I can't figure it out myself.
What I would like to end up is, get the total calculation of the work time hours for each name only for the month written in A5 cell.
So far I used this code to have the start date Monday, based on the date in A5 cell.
=A5-MOD(A5-2,7)
With this community help I ended up with this code to count the work time for each name in the week (lots of students in the schedule)
=SUMPRODUCT(IFERROR(TIMEVALUE(MID(C7:H7,FIND("-",C7:H7,1)+1,LEN(C7:H7)-FIND("-",C7:H7,1))) - TIMEVALUE(LEFT(C7:H7,FIND("-",C7:H7,1)-1)),0))
The help I need, if it's possible, is to figure out how to get the total work time only for the month entered in cell A5 (which is 1.october - 31.october) without counting the last 3 days in September. I plan to use this spreadsheet for the following months as well. I tried to use COUNTIFS, but no luck so far. Also, I am using an online excel version, which is very limited in the menu.
Thanks in advance for any help.
=TEXT(c6, "mmm") will give Sep, while TEXT(A5, "mmm") will give Oct. You need to SUMIF the month matches.
You could incorporate this together with the equation you already have but I think it might be easier to create a duplicate table below the main table, copying the day of the month and the names and using your above mentioned equation to get the hours to be summed.
Either above or below the date, or instead of the date, I'd pull out the month with =TEXT(C6, "mmm")
Lets say the duplicate table for cells B16-I12 was in cells B106-I112 with the extra row specifying the month above this in row 105 (=TEXT(C106, "mmm") etc.).
Then in cell D24, you'd have
=SUMIF(C$105:I$105,TEXT($A$5,"mmm"),C107:I107) +[same again for the next week, cells B15-I21] + [same again for the next week] etc.
This can then be copied down for all the names.
You could also feed this information up into cells K7, K8,K12, becuase you only need this for the first and last months. So J6 would read 'hours this week' K6 would read Hours last month, L6, hours this month. Then D24 could sum L7 and J16 etc.

Excel formula to say if time is within a certain hourly range

I have a column(A) of times, stored in time format. And I have columns(B-M) of hourly times, 08:00:00 - 09:00:00 etc. I want Excel to put a 1 in the correct hourly column based on the time, and hopefully a zero in all the others. I thought COUNTIFS could do this, I tried
=COUNTIFS(A2, ">=08:00:00", A2, "<09:00:00") So if the time is between 8 and 9am I would get a 1 in column B. Obviously it didn't work, hence why I'm here.
Excel book 1
You can use this formula
=AND($A2>=TIMEVALUE(LEFT(B$1,5)),$A2<TIMEVALUE(RIGHT(B$1,5)))
Put it in B2 and pull it downwards and sideways. This takes the time ranges from the first row and looks if the time from the first column is inside the current range.
If you don't want True or False(in the example pictures it's in german) you can multiply the formula by 1 to get 0 and 1 as results or wrap an if around to get any desired output.

Employee schedule - Calculate total hours from time in 1 cell; auto format time

I have an existing employee schedule excel file to which I'd like to make "smarter."
For each employee, time is entered in one cell (e.g. 7AM-3PM) for each day of the week. I would like to have the Total Hours for each employee calculated at the end of the week. I have a formula that does that, but it brings up additional problems.
=((SUBSTITUTE(B4,LEFT(B4,FIND("-",B4)+1),"")*1-SUBSTITUTE(B4,RIGHT(B4,FIND("-",B4)-1),"")*1)+(SUBSTITUTE(B4,LEFT(B4,FIND("-",B4)+1),"")*1<SUBSTITUTE(B4,RIGHT(B4,FIND("-",B4)-1),"")*1))*24
Here, the time is entered in cell B4 and this formula is pasted in the cell that you would like to have calculate the total hours.
In this formula, the time needs to be entered in the format "XX:XX AM - XX:XX PM" otherwise it doesn't work. Also if a cell is blank or says OFF, it again doesn't work. So what I would like is to automatically convert times entered in any cell as "7AM-3PM" to the format "7:00 AM - 3:00 PM."
Also, if a cell value is blank or says OFF, for it to consider the value of the cell to be "00:00 AM - 00:00 AM" but still be displayed as blank/OFF.
The way I am calculating the total hours for the week is summing up the formula above for each day (it becomes very long and I'm not sure if this is the best way to do it).
Any help for this would be appreciated.
This will take your entry and do what you want:
=IFERROR(TRIM(SUBSTITUTE(SUBSTITUTE(MID(A1,FIND("-",A1)+1,LEN(A1)),"AM"," AM"),"PM"," PM")) -TRIM( SUBSTITUTE(SUBSTITUTE(LEFT(A1,FIND("-",A1)-1),"AM"," AM"),"PM"," PM")),0)

Resources