cancel
Showing results for
Did you mean:
Regular Visitor

## Round time DOWN to the nearest 5/15/30 minutes

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).

eg:
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.

1 ACCEPTED SOLUTION

Accepted Solutions
New Contributor

## Re: Round time DOWN to the nearest 5/15/30 minutes

Would grouping the data into a new column using 15 minute bins not work for what you need to do?

12 REPLIES 12
New Contributor

## Re: Round time DOWN to the nearest 5/15/30 minutes

Would grouping the data into a new column using 15 minute bins not work for what you need to do?

Highlighted
Regular Visitor

## Re: Round time DOWN to the nearest 5/15/30 minutes

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?

Regular Visitor

## Re: Round time DOWN to the nearest 5/15/30 minutes

@jthomson I've not found bins have worked for my data before but I think in this case, you might be right. I had a feeling there'd be a simpler way.

Established Member

## Re: Round time DOWN to the nearest 5/15/30 minutes

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.

Therefore:

FLOOR(VALUE([Time Val]), 1/96)

Regular Visitor

## Re: Round time DOWN to the nearest 5/15/30 minutes

@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.

Established Member

## Re: Round time DOWN to the nearest 5/15/30 minutes

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

Regular Visitor

## Re: Round time DOWN to the nearest 5/15/30 minutes

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.

Frequent Visitor

## Re: Round time DOWN to the nearest 5/15/30 minutes

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.

Visitor

## Re: Round time DOWN to the nearest 5/15/30 minutes

Good solution - This worked best for me but I think you're missing the MINUTE() function in the top solution.

Announcements

#### Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

#### Community News & Announcements

Get your latest community news and announcements.

#### Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

#### Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Top Kudoed Authors
Users Online
Currently online: 399 members 3,339 guests
Recent signins: