Written By Rick de Groot

Rick is the founder of BI Gorilla. He believes learning is one of life's greatest pleasures and shares his knowledge to help you improve your skills.

Have you ever wanted to know exactly when your data was last updated in Power BI? It’s important to know when your data is accurate and up-to-date. But, did you know the built-in Power Query method for finding the last refresh time is not always reliable?

Especially when your refresh takes place in a different time zone. In this article, we’ll show you a simple and reliable way to create a last refresh datetime value in Power BI, that takes into account the correct daylight savings time. So you can be sure your data is accurate and up-to-date all the time. Let’s get started!

Table of contents
Create Last Refresh Time that respects Daylight Saving in Power Query

Retrieve Local DateTime

The easiest way to create a last refresh datetime value in Power BI is by using Power Query. Most solutions I find use the DateTime.LocalNow function to get the current date and time:

= DateTime.LocalNow() // Returns the current DateTime value of your machine

The DateTime.LocalNow function returns the current date and time of the machine where the refresh takes place. In some situations, this returns the expected results, but beware! You may not always get the expected value when you publish your report to the Power BI service.

When you configure your report with a scheduled refresh, it may be that the location where your report refreshes is in a different country than where your users live.

You can check this by going to the Power BI Service.

About Power BI Settings

Click the Question Mark in the top right corner -> click About Power BI.

Last Refresh Location Dataset

You now get a pop-up that shows details about your Power BI tenant. One of these lines shows where your data is stored in, followed by the location.

Here’s the thing. The location where the scheduled refresh takes place impacts the datetime value returned by the DateTime.LocalNow function. In the above picture, the data resides in Ireland.

The last refresh Date Time stamp in your Power BI report, therefore, shows the time in Ireland. In the Netherlands, where I live, daylight saving time is always 2 hours ahead of Ireland. Therefore, reports show the wrong time.

So, how can we handle this so the function always returns at the right time? And how do we make sure the time accounts for the Daylight Savings time, too (GMT + 1 in winter and GMT + 2 in summer)?

Fix: DateTimeZone with Daylight Saving

The key to making this work is to make use of the DateTimeZone.UtcNow() function. This function returns the UTC (Universal Time Coordinated) value, previously known as GMT. No matter the location of your machine, this function always returns GMT + 0 / UTC time.

For retrieving both the DateTimeZone value and the UTC Date, you can then use the following:

=  UTC_DateTimeZone = DateTimeZone.UtcNow()
=  UTC_Date         = Date.From( UTC_DateTimeZone )

The trick is to convert UTC to the local time. To do that, you need to account for Daylight Saving Time (winter and summertime). For the logic, we need to know the start of each period. So when do they both start?

  • Summertime starts on the last Sunday of March
  • Wintertime starts on the last Sunday of October

It’s a little tricky to get that date but bear with me. To find the last Sunday in March, you can do the following:

= #date( Date.Year( UTC_Date ), 3, 31 )           // Returns last date in March
= Date.StartOfWeek( LastSundaymarch, Day.Sunday ) // Returns latest Sunday in March

You can easily combine these to find the Start of both the winter- and summertime:

  StartSummerTime = Date.StartOfWeek( #date( Date.Year( UTC_Date ), 3, 31),  
                                      Day.Sunday ) 
  StartWinterTime = Date.StartOfWeek( #date( Date.Year( UTC_Date ), 10, 31 ), 
                                      Day.Sunday ) 

You now need to define how much the time should be offset. The Netherlands uses UTC + 2 in Summertime and UTC +1 in wintertime. You can add a variable returning the offset value:

= if UTC_Date >= StartSummerTime and UTC_Date < StartWinterTime 
    then 2 else 1

With this in mind, you can now return the last updated timestamp by offsetting the UTC time with the relevant number of hours. The function for this is DateTimeZone.SwitchZone.

= DateTimeZone.SwitchZone( UTC_DateTimeZone, UTC_Offset )
// Returns the current datetime value respecting Daytime Saving hours

And that’s the last piece of the puzzle to turn UTC to local for your last refresh date in Power BI.

Code Fix: Last Refresh Date

When you put all of this together, you get the following script:

  UTC_DateTimeZone = DateTimeZone.UtcNow(), 
  UTC_Date         = Date.From(UTC_DateTimeZone), 
  StartSummerTime  = Date.StartOfWeek(#date(Date.Year(UTC_Date), 3, 31), Day.Sunday), 
  StartWinterTime  = Date.StartOfWeek(#date(Date.Year(UTC_Date), 10, 31), Day.Sunday), 
  UTC_Offset       = if UTC_Date >= StartSummerTime and UTC_Date < StartWinterTime then 2 else 1, 
  CET_Timezone     = DateTimeZone.SwitchZone(UTC_DateTimeZone, UTC_Offset)

This returns the correct DateTime value regardless of the machine that performs the scheduled refresh. And that should give us some peace of mind.

You can also allow your users to provide the summertime and wintertime offsets by offering them a function. This is useful in case you need a template that needs to work for multiple time zones.

(Summer_GMT_Offset as number, Winter_GMT_Offset as number) =>
    UTC_DateTimeZone = DateTimeZone.UtcNow(),
    UTC_Date = Date.From( UTC_DateTimeZone ),
    StartSummerTime = Date.StartOfWeek( #date( Date.Year( UTC_Date ) , 3 , 31 ), Day.Sunday ),
    StartWinterTime = Date.StartOfWeek( #date( Date.Year( UTC_Date ) , 10, 31 ), Day.Sunday ),
    UTC_Offset = if UTC_Date >= StartSummerTime and UTC_Date < StartWinterTime then Summer_GMT_Offset else Winter_GMT_Offset,
    CET_Timezone = DateTimeZone.SwitchZone( UTC_DateTimeZone, UTC_Offset)


So there you have it, a simple and reliable way to create a last refresh datetime value that takes into account daylight savings time. Now, you can be sure that your data is accurate and up-to-date, even during the times of the year when the clocks change.

Remember, the built-in Power Query method using the DateTime.LocalNow function can be unreliable, so this method is the preferred one. Give it a try and see how it works for you! Keep in mind that this approach can be applied to other similar scenarios to make sure your data is accurate and reliable.

And with that, your report refresh time should always return the right value. Enjoy Power Query!

Share on:

Latest from my blog

  1. When working for an executive with direct reports in the US, Ireland, and Australia, I found that DST comes and goes on different weeks in each of those countries so anybody looking to generate a DST solution should consult a reference such as timeanddate.com, where you can find not only the recent and next dates of DST but the rules. I’ve poked at a few solutions involving USERPRINCIPALNAME() and a user/location mapping table to show each user his/her local refresh time.

    • Ken,

      That’s a great idea. It would make for a really interesting solution. You could create a UTC time, and have the offsets for summer and wintertime in a table. Then write your DAX with RLS that takes into account the accounts that logs in.

      You mention having poked at a few solutions. Did they work in the end?

    • This should help you out. And feel free to change the offset numbers to fit your Timezone. It should work for any Daylight Saving Time 😁👌


Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.