I couldn't find anything on actually rounding time intervals down to the nearest X.
This is necessary to aggregate time data.
MROUND only rounds to the nearest specified multiple (so also rounds up).
MROUND( 00:07:00, 15) = 0
MROUND( 00:08:00, 15) = 15
Really we want any time between 00:00:00 and 00:14:59 to round down to 00:00:00, any time between 00:15:00 and 00:29:59 to round down to 00:15:00, etc.
Solved! Go to Solution.
I'm going to attempt to answer my own question here...
FLOOR seems to work for this (I'd initially assumed it'd work like ROUND and work on the number of digits):
TIME( HOUR( Time[Time] ), FLOOR( Time[Time], 5 ), 0 )
This will round down to the 5 minute level.
I think this will work with 1, 2, 3, 4, 5, 10, 20, 15 or 30. I don't think it would work with odd intervals like 7 or 45 because it will reset on the next hour. For 45, you'd get 0 for everything between 00:00:00 and 00:44:59 and 45 for everything between 00:45:00 and 00:59:59.
Another alternative is to use SWITCH( TRUE(), [...]
eg for 5 minute intervals:
5 min = TIME( HOUR( Time[Time] ), SWITCH( TRUE(), MINUTE( Time[Time] ) >= 55, 55, MINUTE( Time[Time] ) >= 50, 50, MINUTE( Time[Time] ) >= 45, 45, MINUTE( Time[Time] ) >= 40, 40, MINUTE( Time[Time] ) >= 35, 35, MINUTE( Time[Time] ) >= 30, 30, MINUTE( Time[Time] ) >= 25, 25, MINUTE( Time[Time] ) >= 20, 20, MINUTE( Time[Time] ) >= 15, 15, MINUTE( Time[Time] ) >= 10, 10, MINUTE( Time[Time] ) >= 5, 5, MINUTE( Time[Time] ) >= 0, 0 ), 0 )
Does anyone have any pointers here or is this about right?
I'm not sure if you're talking about a time of day, or a measurement of time? Time is stored as an decimal between 0 and 1, so each 15 mins is equal to (1/24/60)*15, which is the same as 1/96.
FLOOR(VALUE([Time Val]), 1/96)
@SteveCampbell In this case, I was trying to make a 'calendar' table for time of day.
I didn't know exactly how time was stored before. That might also explain why I've had issues with drag filling in excel.
If using for time of day, FLOOR(VALUE([Time Val]), 1/96) will work if you set to time and select the correct formatting. if it is a measurment of time, sorting it as time will be difficult after you get past 24 hours. Here it would be much better to just store as a value (such as seconds).
Interestingly - date / time is just a number, with 0 being 12:00:00am on 12/30/1899.
Each day is a value of 1, and time is just the decimal of how much through the day we are. At 11/27/17 10:00:00am it is 43066.4166666, so 43066 days after 12/30/1899, and .416666 through the current day
Interesting way of doing it. I think bins is the simplest solution in Power BI though. I've stored the date as a separate column for my data so I can just group the data by time and filter by dates separtely.
You can still use MROUND() function.
=MROUND( [Time], "0:15" ) -- this will round up/down to 15 min.
Just remember that Mround will not recognise your column with time as time. So if you see a decimal number returned by MROUND(), don't panic just change the data type to Time on your new column.