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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Anonymous
Not applicable

How to remove milliseconds or round to nearest second

So I have a column of date times in a SQL Server databas as per below:

 

2019-06-20 06:02:55.667
2019-06-20 06:02:55.433
2019-06-20 06:20:00.083
2019-06-20 06:20:00.053
2019-06-20 06:20:00.130

 

When I create a model in SSAS I get the following rows:

 

6/20/2019 6:02:55 AM
6/20/2019 6:02:55 AM
6/20/2019 6:20:00 AM
6/20/2019 6:20:00 AM
6/20/2019 6:20:00 AM

 

At first glance the miliseconds no longer appear. However, when I try to do aggregations based on the date I actually get incorrect results because the miliseconds make these rows appear all different.

 

What I actually want is to find a way to remove the milliseconds from the datetime. I have tried using the DAX FORMAT function however it actually rounds up the miliseconds and I get the followign results:

 

20/06/19 06:02:56
20/06/19 06:02:55
20/06/19 06:20:00
20/06/19 06:20:00
20/06/19 06:20:00

 

As you can see the first two rows now have 56 and 55 seconds. This is because the milliseconds get rounded up.

 

How can I create a new column which actually has 55 seconds for both first and second row? Is there a way to tell the DAX function to round down the milliseconds? Or just remove them completely?

 

Thank you

 

 

4 REPLIES 4
Anonymous
Not applicable

Hi! In my case I want to use the rounded up values, can you let me know how did you achieve that?

HotChilli
Super User
Super User

Is this Power BI ? If so, in Power Query you can Split column on the last occurrence of '.' (This must be before the data type is changed to DateTime (or similar).

 

If not, I think you can use the same Power Query functionality in newer versions of Analysis Services.

Anonymous
Not applicable

Yes, it is indeed Power BI. However, it is a live connection from SSAS. As such, all the data modelling needs to happen in SSAS.

 

But you might be onto something there with splitting the column. I will try that out. However, the issue is that the milliseconds do not actually appear in SSAS (but they exist somewhere in the back as they are taken in consideration when doing calculations, distinct etc.).

Anonymous
Not applicable

let
    Source = "2019-06-20 06:02:55.667",
    SourceToDateTimeFormat = DateTime.FromText(Source)
in
    SourceToDateTimeFormat

Just tried this out of curiosity. The code above is giving the output "20-06-2019 06:02:55". 

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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