Excel SUMPRODUCT with ISNUMBER and TIMEVALUE and LEFT to meet criteria - excel-formula

In Cell D$3$:D$38$ I have
## Heading ##
Thu Oct-05
Off
Off
Off
Maternity
Off
Off
Off
Off
Off
Off
VACATION
04:00-16:00
04:00-14:00
05:00-14:00
05:00-14:00
06:00-16:00
06:00-15:00
07:00-17:00
07:30-16:30
07:30-16:30
08:00-17:00
08:00-17:00
08:00-18:00
08:00-17:00
08:00-18:00
09:00-18:00
09:30-18:30
10:00-19:00
10:00-19:00
10:30-19:30
10:30-19:30
11:00-20:00
12:00-22:00
13:00-22:00
13:00-22:00
15:00-22:00
I used the formula
=SUMPRODUCT(--(ISNUMBER(TIMEVALUE(LEFT($D$3:$D$38,5)))))
to successfully obtain the result of 25 cells with number in the specified range but when I try to add a criteria like:
>=ISNUMBER(TIMEVALUE(B44)) and B44 is 4:00 am and the second criteria <=ISNUMBER(TIMEVALUE(c44)) B44 is 5:00 am
I'm not able to get the result I should that's: 2
Do you know why it is not working the way it should?
Thank You

You can change the formula to this:
=SUMPRODUCT(--(ISNUMBER(TIMEVALUE(LEFT(TEXT($D$3:$D$50,"hh:mm:ss"),5)))))
The reason it doesn't recognize 4:00 am or 5:00 am is due to TIMEVALUE evaluate time text and therefore, you need to convert it to time text first.

Related

Finding earliest date in excel

In one column I have to 10 times and dates (I have merged date and time in a cell). How do I find top 5 earliest dates and times? I can’t use function MIN() because I have date and time together. How should I write the function?
You need to first format your data in date/time format in Excel.
Example, the following data is entered
16/7/2018 15:00
18/7/2018 12:05
25/8/2018 11:00
13/7/2018 09:00
15/7/2018 14:00
15/7/2018 11:00
You can use the formula =small(range, rank) to find the smallest n figure. For instance, =SMALL($A$1:$A$6,1) would give the smallest (earliest) date, 13/7/2018 09:00 in this case. =SMALL($A$1:$A$6, 2) would give the second smallest (earliest) date, 15/7/2018 11:00 in this case.

SUM interval of rows even if error

i'm trying to sum values but when a cell as an error, id like that to count as a 0, and continue adding.
the values in the cells are 15:60, or 8:00, "h:mm"
i've tried this:
{=SUM(IF(ISERROR(A1:A7);0;A1:A7))}
but it gives me a weird value
example:
15:00
06:00
gives me 0,875?
i just want it to add, 15:30 + 15:30, should give 31:00
thx in advance!
[SOLVED] change the cell type to TIME 37:30:55
21/24 = 0.875
The result is 21:00 but in float number, the normal way for Excel to store time.
The same with date times, they are also stored that way.
Integer (whole numbers) as the number of days since 1/1/1900 and the fraction as the time.
Most likely all you need to do is to change the format of the cell to time and it will be displayed correct.

Adding/Subtracting Whole numbers from Time

I have tried every which way to format cells to subtract the result from time for instance the formula in the cell = 11(this is 11 minutes) I want to take that result minus 8:00:00 to give me 7:49:00 but it doesn't work the result is ####### no matter how big I make the cell. And if I format the cells with the formula to custom [m]:ss then the value changes.
Sample of the Worksheet:
I want Y2 = X3-W3 in a time format.
So, if A1=11
Then in some other cell, (B1 in this example): =TIME(,A1,)
Then subtract from the cell with 8:00:00. (If it's C1...:)
=C1-B1
That will give you the time you want.
Info: The main thing is that you have to tell Excel that your cell with the "11" in it, is minutes. By using the =TIME(,A1,) you will get the value of: 12:11 am. (If you keep it in Date format.) 12:11 am could also be viewed as: 0 Hours, 11 minutes, 0 seconds. And now that it knows, you should be able to subtract.
Try this:
=TIME(HOUR(X3),MINUTE(X3)-W3,SECOND(X3))
The ######### is because you have a negative time. Becuase Excel reads time as decimals of 24 hours, 8:00:00 is .3333 and if you subtract 11 from that you get -10.6666 and date/time can not be negative.

How to mass copy rows depending on a counter in either SPSS or excel

The problem I have is as such:
I have a database full of xrays and associated information for a long list of patients, ordered by patient ID. What I want to do is to find the time of the first xray performed for each patient, and I want to fill this in for each xray of these patients. The issue is that each patient often has multiple xrays, and I'm not sure how to copy the data from another column into my timeOfFirstXray column.
For example; (sorry for my very poor formatting)
ptid ...dateandtimeofxray .....dateandtimeof1stXRAY
4 .......21/1/2011 4:30 ............21/1/2011 4:30
4 .......22/2/2011 5:11 ...........21/1/2011 4:30
4 .......25/5/2011 5:00 ........... 21/1/2011 4:30
5 .......29/7/2000 3:00 ............ 29/7/2000 3:00
5 .........30/7/2000 4:00 ......... 29/7/2000 3:00
5 ........ 31/7/2000 5:00 ......... 29/7/2000 3:00
5 .........1/8/2000 1:00 ........... 29/7/2000 3:00
6 .........1/9/2002 2:00 ........... 1/9/2002 2:00
8 ........ 3/10/2008 3:23 ......... 3/10/2008 3:23
8 .........4/10/2008 5:00 ......... 3/10/2008 3:23
8 ........ 5/10/2008 9:00 ......... 3/10/2008 3:23
My psuedocode is:
Set a counter to 0
initialise date variable to first row's date value
foreach row,
if counter < patientID, counter++ until equal with id, set date variable to value of date in this row, and set this value to timeOfFirstXray for the row.
else if counter == patientID, copy existing value in date variable into timeOfFirstXray for this row
I've never used SPSS or excel for this type of stuff before, so basically what I'm looking for is the above translated.
Thankyou for reading!
Here is an SPSS option.
`do if (missing(lag(ptid)) or ptid ne lag(ptid)).
compute dateandtimeof1stxray = dateandtimeofxray.
end if.
leave dateandtimeof1stxray.`
This presumes that dateandtimeof1stxray does not exist in the input dataset.
HTH,
Jon Peck
Here's an Excel option. Assuming your data starts in row 2, enter this formula in C2 and copy down. Note that this is an array formula and must be entered with Ctrl-Shft-Enter. (If done correctly you'll see curly braces around the formula.) Then just copy down as far as needed:
=MIN(IF(($A$2:$A$12=A2)*($B$2:$B$12),$B$2:$B$12))
Adjust your ranges to fit you data. Note that it gets the earliest date even if they're not in chronological order in your source data.
If you are interested in the logic behind the formula, see this post on my blog.
If you wanted to just show the minimums, you could accomplish something similar to Andy W's comment above by using a pivot table in Excel (Excel 2010 shown here). The key is to "show the values as" Min:

Excel - Date Range includes given time of day (a better approach)

Given a set of DateTime ranges in excel, such as:
Start Finish
13/03/2012 10:00:00 14/03/2012 03:00:00
15/03/2012 08:30:00 15/03/2012 10:00:00
And some TimeSpan such as:
Start Finish
07:00:00 09:00:00
How would you determine if the time span falls in some given date range?
An approach like this might be a start:
AND(B2 < DATEVALUE(TEXT(B2, "dd/mm/yyyy")) + TIMEVALUE("07:00:00"),
B3 >= DATEVALUE(TEXT(B3, "dd/mm/yyyy")) + TIMEVALUE("09:00:00"))
Though it relies on the being able to provide the start/finish values explicitly as opposed to two dates in any order. A conditional on start <= finish would do, but seems like it's overly complicated.
Is there a better way?
Edit: Bonus points for a simple approach to finding the percentage of the date range that falls in the time span
Seems like you're assuming that the dates will always be the same day, is that the case?
Try
=AND(MOD(A2,1)<=F2,MOD(B2,1)>=G2)
For percentage
=MAX(0,MIN(MOD(B2,1),G2)-MAX(MOD(A2,1),F2))/(B2-A2)
Update:
If the date range can be unlimited, 1 day or many, then you can use this formula to get the total hours within the timespan
=(INT(B2)-INT(A2))*(G$2-F$2)+MEDIAN(F$2,G$2,MOD(B2,1))-MEDIAN(MOD(A2,1),G$2,F$2)
that assumes that the timespan doesn't cross midnight - if timespan may cross midnight, e.g. could be 08:00 - 11:00 but could also be 22:00 - 03:00 then this formula should work
=(F$2>G$2)*(B2-A2)+SIGN(G$2-F$2)*((INT(B2)-INT(A2))*ABS(G$2-F$2)+MEDIAN(F$2,G$2,MOD(B2,1))-MEDIAN(MOD(A2,1),G$2,F$2))
This should give the number of hours falling in the time span (but it's definitely not simple!):
=MEDIAN(F2,G2+(G2<F2),MOD(B2,1)+(MOD(B2,1)<MOD(A2,1)))
-MEDIAN(F2,G2+(G2<F2),MOD(A2,1))
+(F2<G2)*(MOD(B2,1)<MOD(A2,1))*MAX(MIN(MOD(B2,1),G2)-F2,0)
If this is greater than 0, the date range falls in the time span, divide this by B2-A2 for the percentage.
e.g. Date Range: 6:00PM - 9:00AM, Time span: 7:00AM - 7:00PM returns 03:00 which is 20% of the date range.
Say the date ranges are in columns A and B, and the Timespan in F2 and G2.
Apply the following formulas and drag down.
H2 = IF(AND($F$2>=RIGHT(A2,8),$F$2<RIGHT(B2,8),$G$2>RIGHT(A2,8),$G$2<=RIGHT(B2,8)),1,0)
Column H gives tells you if it's true for a particular date range.
I1 = SUM(H2:H4)/COUNT(H2:H4)
I1 gives you the percentage

Resources