skip to main content
Power BI
    • What is Power BI
    • Why Power BI
    • Customer stories
    • Data visuals
    • Security
    • Power BI Desktop
    • Power BI Pro
    • Power BI Premium
    • Power BI Mobile
    • Power BI Embedded
    • Power BI Report Server
  • Pricing
    • Azure + Power BI
    • Microsoft 365 + Power BI
      • Energy
      • Healthcare
      • Manufacturing
      • Media
      • Retail
    • For analysts
    • For IT
      • Overview
      • Embedded analytics
      • Power BI visuals
      • Automation
      • Documentation
      • Community
    • Overview
    • Find consulting services
    • Partner showcase
    • Find a partner
    • Become a partner
    • Instructor-led training
    • Getting started
      • Overview
      • Online workshops
      • Self-guided learning
      • Webinars
      • Documentation
      • Roadmap
      • Overview
      • Issues
      • Give feedback
    • Blog
    • Business intelligence topics
    • Overview
    • Forums
    • Galleries
    • Submit ideas
    • Events
    • User groups
    • Community blog
    • Register
    • ·
    • Sign in
    • ·
    • Help
    Go To
    • Galleries
    • Community Connections & How-To Videos
    • COVID-19 Data Stories Gallery
    • Themes Gallery
    • Data Stories Gallery
    • R Script Showcase
    • Webinars and Video Gallery
    • Quick Measures Gallery
    • 2021 MSBizAppsSummit Gallery
    • 2020 MSBizAppsSummit Gallery
    • 2019 MSBizAppsSummit Gallery
    • Events
    cancel
    Turn on suggestions
    Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
    Showing results for 
    Search instead for 
    Did you mean: 
    • Microsoft Power BI Community
    • Galleries
    • Quick Measures Gallery
    • Re: Milliseconds Duration

    Re: Milliseconds Duration

    09-07-2022 02:05 AM

    HJC-AC
    Frequent Visitor
    1715 Views
    LinkedIn LinkedIn Facebook Facebook Twitter Twitter
    Greg_Deckler
    Super User Greg_Deckler
    Super User
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    Milliseconds Duration

    ‎04-29-2018 09:07 AM

    Based on the original blog post around Duration from 1/25/16 by @konstantinos and later blogged about here:

    https://community.powerbi.com/t5/Community-Blog/Aggregating-Duration-Time/ba-p/22486

     

    Extends the formatting of Duration to include milliseconds.

     

     

    Duration Milliseconds = 
    // Duration formatting 
    // * Based on @konstatinos and @Greg_Deckler blog post 
    // https://community.powerbi.com/t5/Community-Blog/Aggregating-Duration-Time/ba-p/22486 1/25/2016
    // * Given a number of milliseconds, returns a format of "hh:mm:ss:000 format"
    //
    // We start with a duration in number of milliseconds
    VAR Duration = SUM(Milliseconds[Milliseconds])
    // There are 3,600,000 milliseconds in an hour
    VAR Hours = INT ( Duration / 3600000)
    // There are 60,000 milliseconds in a minute
    VAR Minutes = INT ( MOD( Duration - ( Hours * 3600000 ),3600000 ) / 60000)
    // There are 1000 milliseconds in a second  
    VAR Seconds = INT (MOD ( MOD( Duration - ( Hours * 3600000 ) - (Minutes * 60000),60000 ), 60000 ) / 1000)
    VAR Milli = ROUNDUP(MOD(MOD ( MOD( Duration - ( Hours * 3600000 ),3600000 ), 60000 ), 1000),0)
    // These intermediate variables ensure that we have leading zero's concatenated onto single digits
    // Hours with leading zeros
    VAR H =
        IF ( LEN ( Hours ) = 1, 
            CONCATENATE ( "0", Hours ),
            CONCATENATE ( "", Hours )
          )
    // Minutes with leading zeros
    VAR M =
        IF (
            LEN ( Minutes ) = 1,
            CONCATENATE ( "0", Minutes ),
            CONCATENATE ( "", Minutes )
        )
    // Seconds with leading zeros
    VAR S =
        IF (
            LEN ( Seconds ) = 1,
            CONCATENATE ( "0", Seconds ),
            CONCATENATE ( "", Seconds )
        )
    // MilliSeconds with leading zeros
    VAR MS =
        IF (
            LEN ( Milli ) = 1,
            CONCATENATE ( "00", Milli ),
            IF (
               LEN (Milli) = 2,
               CONCATENATE("0", Milli),
               CONCATENATE ( "", Milli )
            )
        )
    // Now return hours, minutes and seconds with leading zeros in the proper format "hh:mm:ss"
    RETURN
        CONCATENATE (H,CONCATENATE ( ":", CONCATENATE ( M, CONCATENATE ( ":", CONCATENATE(S, CONCATENATE(":", MS ) ) ) ) ) )

     

     

    eyJrIjoiMzgwMWM4YzQtNmFhNy00NGI0LThiNjItZTMzMzAyYWQ2YTkyIiwidCI6IjRhMDQyNzQzLTM3M2EtNDNkMi04MjdiLTAwM2Y0YzdiYTFlNSIsImMiOjN9


    @ me in replies or I'll lose your thread!!!
    Instead of a Kudo, please vote for this idea
    Become an expert!: Enterprise DNA
    External Tools: MSHGQM
    YouTube Channel!: Microsoft Hates Greg
    Latest book!:
    Mastering Power BI 2nd Edition

    DAX is easy, CALCULATE makes DAX hard...
    Milliseconds.pbix
    28 KB
    Labels:
    • Labels:
    • Time Intelligence
    Message 1 of 6
    10,968 Views
    1
    Reply
    • All forum topics
    • Previous Topic
    • Next Topic
    HJC-AC
    HJC-AC
    Frequent Visitor
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎09-07-2022 02:05 AM

    Building on this in a simpler format, if you have a timestamp in milliseconds and want to convert it to a datetime:ms, then please see below. This is also incorporating the work from here https://community.powerbi.com/t5/Desktop/Parse-timestamps-to-date/m-p/155179

     

     

    UTCTime = VAR msTimestamp = 'table'[timestamp]
    VAR UnixDays = msTimestamp/(60*60*24*1000)
    VAR Milli = RIGHT(msTimestamp,3)
    VAR DateTime = (DATEVALUE("1/1/1970") + UnixDays)
    RETURN CONCATENATE (FORMAT(DateTime, "dd/mm/yyyy hh:MM:ss"), CONCATENATE( ":", Milli))

     

    Message 6 of 6
    1,715 Views
    0
    Reply
    vissvess
    vissvess Helper V
    Helper V
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎07-22-2019 03:59 AM

    Dear @Greg_Deckler ,

     

    The code does well..
    I tried it with my case where I need to plot the duration against a category where the duration is in hh:mm:ss:000 format.

     

    When the same is tried for execution, the Y axis is shown as fractional number.

     

    Any help would be appreciated.

     

    Thanks

    Message 5 of 6
    9,463 Views
    0
    Reply
    davorgom
    davorgom
    Frequent Visitor
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎04-30-2018 10:36 AM

    HI @Greg_Deckler

     

    Thanks to your help. Your comments are very helpful.

     

    I wanna say you that the idea is getting well, but I have problems with milliseconds to minuts. I don´t know if Im wrong.  As you can see at the files attached, in a 100m race, a runner made 12.40 sgs, and it appears 12:400, its ok. But when the result is in minutes, for example a 1500m race, where the runner has 33:29.71, power bi shows 5:32:971.  The graphs appears wrong too. There is a possibiity to improve this?

     

    On another hand, when I try to graph the places of the 100m record,  it shows 12.4mil. There is a possibility to eliminate the text "mil"? Change it for min?

     

    Thanks for your time. Its really important that there is persons who wanna teach anothers to use this app.

     

    Best regards. 

     

    David

    14 KB
    12 KB
    Message 4 of 6
    10,915 Views
    0
    Reply
    davorgom
    davorgom
    Frequent Visitor
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎04-29-2018 06:12 PM

    Hi @Greg_Deckler

     

    I really apreciatte your time and your help. You had sent me a little code but I don`t know how and where can I put this on te app. Can u say me how to do it?

     

    Thanks. 

     

     

    Message 2 of 6
    10,945 Views
    0
    Reply
    Greg_Deckler
    Super User Greg_Deckler
    Super User
    In response to davorgom
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎04-30-2018 05:07 AM

    You can use this formula in a calculated column or in a measure. The only thing that really should need to change is this line:

     

    VAR Duration = SUM(Milliseconds[Milliseconds])

     

    My table is called Milliseconds and my column is called Milliseconds as well.

     

    I attached the PBIX so you can download it and see how it functions.


    @ me in replies or I'll lose your thread!!!
    Instead of a Kudo, please vote for this idea
    Become an expert!: Enterprise DNA
    External Tools: MSHGQM
    YouTube Channel!: Microsoft Hates Greg
    Latest book!:
    Mastering Power BI 2nd Edition

    DAX is easy, CALCULATE makes DAX hard...
    Message 3 of 6
    10,921 Views
    0
    Reply

    Power Platform

    • Overview
    • Power BI
    • Power Apps
    • Power Pages
    • Power Automate
    • Power Virtual Agents

    • Sign in
    • Sign up

    Browse

    • Solutions
    • Partners
    • Consulting Services

    Downloads

    • Power BI Desktop
    • Power BI Mobile
    • Power BI Report Server
    • See all downloads

    Learn

    • Guided learning
    • Documentation
    • Support
    • Community
    • Give feedback
    • Webinars
    • Developers
    • Blog
    • Newsletter

    © 2023 Microsoft

    Follow Power BI

    • Privacy & cookies
    • Manage cookies
    • Terms of use
    • Trademarks
    California Consumer Privacy Act (CCPA) Opt-Out Icon Your California Privacy Choices