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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
hish
Frequent Visitor

Calculating duration between two timestamps with millisecounds

Hello everyone,

 

I am new to Power BI. I am trying to calculate the time difference between two timestamps.

 

In Power Query my timestamp has the following format: 2025-05-13T13:48:28.4970000

 

hish_0-1747293844515.png

hish_3-1747297487579.png

 

 

When uploading my data to Power BI desktop the format of the timestamp is changing to 08.05.2025 13:48:28

 

hish_1-1747297297058.png

 

Unfortnetly, I can not change the format with this in power bi

hish_4-1747297550372.png

 

 

I need the information of the timestamp, because I am calculating the time difference between two timestamps as a new raw.

 

hish_2-1747297449511.png

 

Zeitdifferenz =
VAR AktuellerZeitpunkt = 'Maschinenstatus Schleifen'[Zeitstempel]
VAR Maschine = 'Maschinenstatus Schleifen'[Maschine]
VAR VorherigerZeitpunkt =
    CALCULATE(
        MIN('Maschinenstatus Schleifen'[Zeitstempel]),
        FILTER(
            'Maschinenstatus Schleifen',
            'Maschinenstatus Schleifen'[Maschine] = Maschine &&
            'Maschinenstatus Schleifen'[Zeitstempel] > AktuellerZeitpunkt
        )
    )
VAR Dauer =VorherigerZeitpunkt - AktuellerZeitpunkt
RETURN
IF(
    ISBLANK(VorherigerZeitpunkt),
    BLANK(),
    FORMAT(Dauer, "hh:mm:ss")
)

 

 

 

1 ACCEPTED SOLUTION

Hi @hish ,

 

can you try with below updated dax and let us know if you need anything else i think it will solve your issue

 

TimeDifferenceFormatted =
VAR CurrentTime = 'Machine Status Loops'[Zeitstempel]
VAR CurrentMachine = 'Machine Status Loops'[Maschine]
VAR NextTime =
CALCULATE (
MIN('Machine Status Loops'[Zeitstempel]),
FILTER (
'Machine Status Loops',
'Machine Status Loops'[Maschine] = CurrentMachine &&
'Machine Status Loops'[Zeitstempel] > CurrentTime
)
)
VAR Duration = NextTime - CurrentTime
VAR TotalMs = Duration * 86400000
VAR Seconds = INT(TotalMs / 1000)
VAR MilliSeconds = MOD(TotalMs, 1000)
RETURN
IF (
ISBLANK(NextTime),
BLANK(),
FORMAT(Seconds, "00") & "." & FORMAT(MilliSeconds, "000") & " sec"
)

 

Regards,

Chaithanya.

View solution in original post

8 REPLIES 8
v-kathullac
Community Support
Community Support

Hi @hish ,

As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?

If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

Regards,

Chaithanya

v-kathullac
Community Support
Community Support

Hi @hish ,

As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?

If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

Regards,

Chaithanya

v-kathullac
Community Support
Community Support

Hi @hish ,

As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?

If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

Regards,

Chaithanya

v-kathullac
Community Support
Community Support

Hi @hish ,

Thank you for reaching out to Microsoft Fabric Community Forum.

can you try with below dax and let us know if you need anything else i think it will solve your issue

 

Time Difference =
VAR CurrentTime = 'Machine Status Loops'[Zeitstempel]
VAR CurrentMachine = 'Machine Status Loops'[Maschine]
VAR NextTimestamp =
CALCULATE(
MIN('Machine Status Loops'[Timestamp]),
FILTER(
'Machine Status Loops',
'Machine Status Loops'[Maschine] = CurrentMachine &&
'Machine Status Loops'[Zeitstempel] > CurrentTime
)
)
VAR Duration = NextTimestamp - CurrentTime
RETURN
IF(
ISBLANK(NextTimestamp),
BLANK(),
FORMAT(Duration, "hh:mm:ss")
)

 

Regards,

Chaithanya

This code does still not show me the time differences in milisecounds

Hi @hish ,

 

can you try with below updated dax and let us know if you need anything else i think it will solve your issue

 

TimeDifferenceFormatted =
VAR CurrentTime = 'Machine Status Loops'[Zeitstempel]
VAR CurrentMachine = 'Machine Status Loops'[Maschine]
VAR NextTime =
CALCULATE (
MIN('Machine Status Loops'[Zeitstempel]),
FILTER (
'Machine Status Loops',
'Machine Status Loops'[Maschine] = CurrentMachine &&
'Machine Status Loops'[Zeitstempel] > CurrentTime
)
)
VAR Duration = NextTime - CurrentTime
VAR TotalMs = Duration * 86400000
VAR Seconds = INT(TotalMs / 1000)
VAR MilliSeconds = MOD(TotalMs, 1000)
RETURN
IF (
ISBLANK(NextTime),
BLANK(),
FORMAT(Seconds, "00") & "." & FORMAT(MilliSeconds, "000") & " sec"
)

 

Regards,

Chaithanya.

bhanu_gautam
Super User
Super User

@hish , Try using

Zeitdifferenz =
VAR AktuellerZeitpunkt = 'Maschinenstatus Schleifen'[Zeitstempel]
VAR Maschine = 'Maschinenstatus Schleifen'[Maschine]
VAR VorherigerZeitpunkt =
CALCULATE(
MIN('Maschinenstatus Schleifen'[Zeitstempel]),
FILTER(
'Maschinenstatus Schleifen',
'Maschinenstatus Schleifen'[Maschine] = Maschine &&
'Maschinenstatus Schleifen'[Zeitstempel] > AktuellerZeitpunkt
)
)
VAR Dauer = VorherigerZeitpunkt - AktuellerZeitpunkt
RETURN
IF(
ISBLANK(VorherigerZeitpunkt),
BLANK(),
FORMAT(Dauer, "hh:mm:ss")
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






It is exactly my code with no changes. It is still not working

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.