Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
TessGaston
Regular Visitor

How to round minutes in time to the nearest hour

Hello everybody,

 

I have a field in format of time like 9:03:45 or 9:46:12.

 

I need to make a new field where I would round the times to the nearest hour, for example:

 

9:03:45 -> 9:00

9:46:12 -> 10:00

 

How can I do that in Power BI?

 

Thank you.

Tereza

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @TessGaston

 

You can do this in DAX or M languages depending where you want the calculation to happen.

 

If <original time> is the original time value:

 

DAX:

Round time to nearest hour ( TIME(1,0,0) = 1/24 representing an hour) and add a zero time value to ensure the expression is cast as a Time.

MROUND ( <original time>, TIME ( 1, 0, 0 ) ) + TIME ( 0, 0, 0 )

M:

There isn't an equivalent of MROUND in M, so instead multiply the time by 24 to express it as a number of hours, then round, then divide by 24 and convert to a Time type.

Time.From( Number.Round( Number.From( <original time> ) * 24 ) / 24 )

 Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

3 REPLIES 3
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @TessGaston,

 

Have you solved your problem?

 

If you have solved, please always accept the replies making sense as solution to your question so that people who may have the same question can get the solution directly.

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
OwenAuger
Super User
Super User

Hi @TessGaston

 

You can do this in DAX or M languages depending where you want the calculation to happen.

 

If <original time> is the original time value:

 

DAX:

Round time to nearest hour ( TIME(1,0,0) = 1/24 representing an hour) and add a zero time value to ensure the expression is cast as a Time.

MROUND ( <original time>, TIME ( 1, 0, 0 ) ) + TIME ( 0, 0, 0 )

M:

There isn't an equivalent of MROUND in M, so instead multiply the time by 24 to express it as a number of hours, then round, then divide by 24 and convert to a Time type.

Time.From( Number.Round( Number.From( <original time> ) * 24 ) / 24 )

 Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Thank you very much! Simple and very effective solution

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.