Excel Powerpivot Dax(not native excel)- convert time to decimal hours - excel

I have a list of times:
8:30PM
8:15PM
7:20PM
How can I convert these to decimal hours in Powerpivot (DAX)?
for example:
8.5
8.25
7.33

Use this formula DecimalNumber = Sheet1[DATE]*24, or simply multiply your time with 24. 8:30PM can never evaluate to 8:30 since it is PM, so it's actually 20:50. If you want it to be 8:50 instead, then subtract 12 from formula.

Related

Excel Time Comparison and Subtraction

I am trying to do a time subtraction in excel of 30 minutes and I am running into a speed bump. So the table I have are as follows.
Table "Schedule"
Column 1 is day of the week (Mon-Sun) (formated as general, as this is plain text)
Column 2 is start time of the shift (formated as h:mm AM/PM)
Column 3 is end time of the shift (formated as h:mm AM/PM)
Column 4 is duration of the shift (start to end) (formated by formula (TEXT(col3-col2,"h:mm")) )
Column 5 is paid hours (if the total hours is over 6.5 then subtract 0.5 hours for an unpaid lunch) (formula IF(col5>"6:30",col5-"0:30",D5) )
The issue is any time allotment over 10 hours start to end (where column 4, the duration hits 10 hours) no lunch is subtracted at all.
So...
Start 9:00 AM, End 6:59 PM, Hours Total 9:59, Hours Paid 9:29
But...
Start 9:00 AM, End 7:00 PM, Hours Total 10:00, Hours Paid 10:00
and that should obviously not happen. I can't find anything on google so I figured the excel gurus here may have some advice.
Thanks!
If your time columns are stores using excel's dedicated time format, this should be straightforward. Mixed data types are likely your problem.
First, be sure your time columns (columns 2 and 3) are set using the time function, i.e.,
=time(hours,minutes,seconds)
Then, you should be able to add and subtract easily.
Column 4: = column 3 - column 2
... then subtract 30 minutes also using the time() function:
Column 5: = if(column 4 > time(6,30,0),column 4 -time(0,30,0),column 4)
Excel stores time values from 0 to 1. So 24 hours=1, 12 hours=.5 etc. That means 6.5 hours=0.270833333 and .5 hours=0.020833333. As a result you can just do a simple if statement.
=IF(D2>0.270833333,D2-0.020833333,D2)
To turn it into a time format, is to just use excel's time formating options.

Convert date & time in Excel, to time only, and round to nearest 30 minutes

I need a formula to convert excel date & time to time only and nearest 30 minutes. Example 1/5/2017 4:38:29 PM convert to 1630
A1 B1
1/5/2017 4:38:29 PM 1630
1/5/2017 5:03:40 PM 1700
1/5/2017 4:39:27 PM 1630
I tried if function & vlookup with
=MROUND((TEXT(A1,"hhmm")),1/48)
but I get 0:00 answer, and also
=MOD(Y5,"0:30")
but I get a 0 answer.
It looks like you were almost there. You need MOD to get the decimal portion of a datetime (i.e. the time) then MROUND to the nearest half-hour.
=MROUND(MOD(A1, 1),TIME(0,30,0))
FLOOR and CEILING operate the same as MROUND in case you require the lower or higher half-hour.
You may need to format the cell for the desired time format mask.
Assuming data starts in A1, copy the following down to suit:
=HOUR(A1)&IF(MINUTE(A1)>29,30,"00")

How does Excel convert 12 hour time (text values) into decimal numbers?

I'm trying to find the manual function on how Excel converts am/pm time (text) values into numeric decimals (using the Format menu > Number while selecting my 12 hour time column).
For example, how does 12:30:00 PM turn into 0.52083?
Thank you.
Date and time can be handled in many ways. The time representation you are observing in Excel is based on 1 day = 24 hours = 1.0. So 12:00 pm should be exactly 0.5, while 12:30:00 pm would be a bit (30/(24*60) = 1/48 = 0.0208333) above.
Btw. 12/24 hour is just a region specific presentation issue. Internally this doesn't affect the actual date and time values.

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 convert decimal time to hh:mm time format in excel

I have looked at all the options I can find on this forum, but I am unable to solve my problem. this may very well be because I only have basic excel skills. simple question..how do I convert a decimal time ie 9.25 into hh:mm format ie 09:25 ? I need to do this as I am using existing data that requires rounding to 15 mins + 2mins and I can only do this in hh:mm format. Many thanks
Assuming your value is in A1...
Get the hours
=FLOOR(A1, 1)
Get the decimal portion
=A1 - FLOOR(A1, 1)
Convert this decimal to minutes (0.25->25):
=(A1 - FLOOR(A1, 1)) * 100
Bring the whole lot together:
=TIME(Floor(A1, 1), (A1 - FLOOR(A1, 1)) * 100, 0)
Result: 9:25 AM
If it's a true decimal time then 9.25 hours should convert to 9:15. If that's the case you can just divide by 24, e.g. 9.25 in A1 then in B1
=A1/24
format B1 as [h]:mm and you'll get 9:15
....and if you really do want 9:25 as the answer you could try this formula
=TEXT(A1*100,"00\:00")+0
format result cell as [h]:mm- that will work even for values > 24
If you want you can do your conversion and rounding in one go, e.g. to round to the nearest 15 minutes the first formula becomes:
=MROUND(A1/24,"0:15")
Let's suppose you have 9.25 in cell A1. First you need to extract the integer part (9). Let's put this in B1:
=FLOOR(A1)
Now we must get the decimal part:
=A1-B1
And convert it into the ratio-to-60, so let's have this in C1:
=(A1-B1)/0.6
This way, 0.25 becomes 0.4166... (Of course 0.30 would become 0.50).
Finally, add both values and divide by 24. In Excel, dates/times are stores as decimal numbers in which 1 = 24 hours. So let's place this in D1:
=(B1+C1)/24
The result is 0.392... And if you give that cell a time format, you will see 09:25.
So, now let's put all together in one cell:
=(FLOOR(A1)+(A1-FLOOR(A1))/0.6)/24
Don't forget to format the cell as time (custom format "hh:mm", for example).

Resources