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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
duddys
Helper I
Helper I

Live clock in pbi report

Hi, what is the easiest way to create live clock for my report? Iam in the need because I dont want to refresh the report to get the time, I need it live.

1 ACCEPTED SOLUTION

Hi, change the font color for black:

HTMLContentClock = 
"
<div style='
    width: 100%; 
    height: 100%; 
    padding: 15px; 
    border-radius: 10px; 
    color: black; 
    font-family: Arial, sans-serif; 
    font-size: 30px; 
    font-weight: bold; 
    text-align: center;'>
    <div id='clock'></div>
    <script type='text/javascript'>
        function updateClock() {
            var now = new Date();
            var hours = now.getHours();
            var minutes = now.getMinutes();
            var seconds = now.getSeconds();
            var timeString = hours + ':' + (minutes < 10 ? '0' : '') + minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
            document.getElementById('clock').innerHTML = timeString;
        }
        
        // Update the clock every 1000 milliseconds (1 second)
        setInterval(updateClock, 1000);
        
        // Initial clock update
        updateClock();
    </script>
</div>
"
I hope this helps! 
If you found this answer helpful:
✔️ Mark it as the solution to help others find it faster.
 Give it a like to show your appreciation!

Thank you for contributing to our amazing Power BI community! 

View solution in original post

6 REPLIES 6
v-mengmli-msft
Community Support
Community Support

Hi @duddys ,

 

Do you want to get real-time date without refreshing report or data model? If so, you can try "Deneb" visual.

vmengmlimsft_0-1734340608178.png

 

Here is my test for your reference.

1. Click Edit.

vmengmlimsft_1-1734340676369.png

 

2. Choose one field.

vmengmlimsft_2-1734340769361.png

3. Select "Vega".

vmengmlimsft_3-1734340820562.png

4. Copy below code and run the code.

vmengmlimsft_6-1734341084959.png

{ 
  "$schema": "https://vega.github.io/schema/vega/v5.json", 
  "description": "A simple digital clock visualization showing the current date and time.", 
  "width": "container", 
  "height": "container", 
  "autosize": {"type": "fit", "contains": "padding"}, 
  "signals": [ 
    { 
      "name": "currentDate", 
      "init": "now()", 
      "on": [{"events": {"type": "timer", "throttle": 1000}, "update": "now()"}] 

    }, 

    { 
      "name": "currentYear", 
      "init": "year(currentDate)", 
      "on": [ 
        { 
          "events": {"signal": "currentDate"}, 

          "update": "year(currentDate)" 
        } 

      ] 

    }, 
    { 
      "name": "currentMonth", 
      "init": "month(currentDate)+1", 
      "on": [ 
        { 
          "events": {"signal": "currentDate"}, 
          "update": "month(currentDate)+1" 
        } 

      ] 

    }, 

    { 
      "name": "currentDay", 
      "init": "date(currentDate)", 
      "on": [ 
        { 
          "events": {"signal": "currentDate"}, 
          "update": "date(currentDate)" 
        } 

      ] 

    }, 

    { 

      "name": "currentHour", 
      "init": "hours(currentDate)", 
      "on": [ 

        { 
          "events": {"signal": "currentDate"}, 
          "update": "hours(currentDate)" 

        } 

      ] 

    }, 

    { 

      "name": "currentMinute", 
      "init": "minutes(currentDate)", 
      "on": [ 

        { 
          "events": {"signal": "currentDate"}, 
          "update": "minutes(currentDate)" 
        } 

      ] 

    }, 

    { 
      "name": "currentSecond", 
      "init": "seconds(currentDate)", 
      "on": [ 
        {"events": {"signal": "currentDate"}, "update": "seconds(currentDate)"} 
      ] 

    }, 

    { 
      "name": "fontSize", 
      "value": 24, 
      "on": [ 
        { 
          "events": {"type": "resize"}, 
          "update": "min(width, height) / 20" 
        } 

      ] 

    } 

  ], 

  "marks": [ 

    { 
      "type": "text", 
      "encode": { 
        "enter": { 
          "x": {"signal": "width / 2"}, 
          "y": {"signal": "height / 2"}, 
          "align": {"value": "center"}, 
          "baseline": {"value": "middle"} 
        }, 

        "update": { 
          "text": { 
            "signal": "format(currentYear, '04') + '-' + format(currentMonth, '02') + '-' + format(currentDay, '02') + ' ' + format(currentHour, '02') + ':' + format(currentMinute, '02') + ':' + format(currentSecond, '02')" 
          }, 
          "fontSize": {"signal": "fontSize"} 

        } 

      } 

    } 

  ] 

}

 

The result as below.

vmengmlimsft_7-1734341160058.png

Link: Solved: Re: Create a digital clock in power bi desktop - Microsoft Fabric Community

 

 

Best regards,

Mengmeng Li

 

 

Bibiano_Geraldo
Resident Rockstar
Resident Rockstar

Hi @duddys ,

If you want a live clock that refresh every second like bellow, please consider the following steps:

ezgif-1-c8b278d74d.gif


1 - Download html content visual in appsource.

Bibiano_Geraldo_0-1733837970616.png

 

2- Create a mesure with the following html + css + javascript:

HTMLContentClock = 
"
<div style='
    width: 100%; 
    height: 100%; 
    padding: 15px; 
    border-radius: 10px; 
    color: white; 
    font-family: Arial, sans-serif; 
    font-size: 30px; 
    font-weight: bold; 
    text-align: center;'>
    <div id='clock'></div>
    <script type='text/javascript'>
        function updateClock() {
            var now = new Date();
            var hours = now.getHours();
            var minutes = now.getMinutes();
            var seconds = now.getSeconds();
            var timeString = hours + ':' + (minutes < 10 ? '0' : '') + minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
            document.getElementById('clock').innerHTML = timeString;
        }
        
        // Update the clock every 1000 milliseconds (1 second)
        setInterval(updateClock, 1000);
        
        // Initial clock update
        updateClock();
    </script>
</div>
"

 

 

  • HTML structure: The code creates a div element that will hold the clock and applies some simple styling to display it.
  • JavaScript: The JavaScript function updateClock() fetches the current time, formats it, and updates the content of the div with the ID clock. The setInterval(updateClock, 1000) function ensures that the clock updates every second.
  • Styling: The text is centered and styled with a font size of 30px, and the clock appears bold and clear for readability.

 

 

3- Drag the measure (HTMLContentClock) into the Values field of the HTML Content visual.

 

I hope this helps! 
If you found this answer helpful:
✔️ Mark it as the solution to help others find it faster.
 Give it a like to show your appreciation!

Thank you for contributing to our amazing Power BI community! 

I copied the code, added the visual to my report but all I see is blank white. Its visible only in published report or did I do something wrong

duddys_0-1734432416332.pngduddys_1-1734432434412.png

 

Hi, change the font color for black:

HTMLContentClock = 
"
<div style='
    width: 100%; 
    height: 100%; 
    padding: 15px; 
    border-radius: 10px; 
    color: black; 
    font-family: Arial, sans-serif; 
    font-size: 30px; 
    font-weight: bold; 
    text-align: center;'>
    <div id='clock'></div>
    <script type='text/javascript'>
        function updateClock() {
            var now = new Date();
            var hours = now.getHours();
            var minutes = now.getMinutes();
            var seconds = now.getSeconds();
            var timeString = hours + ':' + (minutes < 10 ? '0' : '') + minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
            document.getElementById('clock').innerHTML = timeString;
        }
        
        // Update the clock every 1000 milliseconds (1 second)
        setInterval(updateClock, 1000);
        
        // Initial clock update
        updateClock();
    </script>
</div>
"
I hope this helps! 
If you found this answer helpful:
✔️ Mark it as the solution to help others find it faster.
 Give it a like to show your appreciation!

Thank you for contributing to our amazing Power BI community! 
danextian
Super User
Super User

Hi @duddys 

You can use UTCNOW() + DIVIDE(offsetvalue, 24) in a measure to get the current time in your timezone. Replace value with your timezone offset. The catch is the user needs to interact with the viz and must not go backk to the previous state of the report as the measure is cached and will return the previous value.










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
mickey64
Super User
Super User

For your reference.

 

Measure = now()

 

mickey64_0-1733835024781.png

 

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.