Power BI – Create Last Dataset Refresh Date
Whilst I have read and found other ways to get the Last Dataset Refresh Date, I find that my method is a lot easier and cleaner to complete.
Creating the Last Dataset Refresh Data
Open Power BI Desktop and go into the Query Editor.
Then click on New Source and select Blank Query
Next I renamed my Blank Query from Query1 to Last Dataset Refresh
Next click on the Advanced Editor and put in the following M Code, which I will explain what it does after the code.
let TodaysDate = DateTime.From(DateTimeZone.SwitchZone(DateTimeZone.FixedLocalNow(),10)), #"Converted to Table" = #table(1, {{TodaysDate}}), #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Last Refresh Date Time"}}), #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Last Refresh Date Time", type datetime}}) in #"Changed Type"
What the above is doing is it is getting today’s Date and time. And this is where I created the magic on the first line.
If you have a look I have put in the Timezone that I am in. I currently am living in Brisbane which is +10 from GMT.
So as you can see from above I have put in 10 for the DateTimezone.SwitchZone, highlighted in BLUE.
The rest of the code converts it to a table, and then I rename the column and finally give it the data type of DateTime.
So the result is the following I created shown below.
I then loaded this into my Power BI Model.
Using the Last Dataset Refresh in your Power BI Reports
Now what I did was I had to create a Calculated Measure, so that I could then use the Last
Dataset Refresh Date.
Below is the Syntax that I used to create my Calculated Measure called Data Last Refreshed
Data Last Refreshed =
VALUES ( 'Last Dataset Refresh'[Last Refresh Date Time] )
Finally I put the measure onto my report and configured it with the Card Visual and the following properties shown below.
I did this to ensure that it would take up the least amount of screen real estate as possible.
And I test it by publishing it to the Power BI Service and it displayed the correct Date and Time.
Conclusion
As you can see this is a simple and effective way to shown when the data in your Power BI Report was last updated.
Any questions or suggestions please feel free to let me know.
This solution works great. The only watch out is for countries where daylight savings time is observed. I’m in New York, so during summer, we are GMT-4, but after summer we are GMT-5. So, unfortunately, the code would produce a time that is off by one hour depending on what I choose (GMT-4 or GMT-5)
Thanks for the comment, I did create another blog post, where you are able to put in when daylight savings starts and ends. And it will automatically make the change for you
Beautiful…
Thankyou so much:)
Glad it assisted you
I receive an “Expression.SyntaxError: Token Identifier exptected.” error message (click on link below to view). Could you please assist? Thanks.
https://drive.google.com/file/d/1xmeZljY9fiqP4KG5zxeNt087dnR9RZvi/view?usp=sharing
Hi Joan,
I found the issue was that the original blog post did not have the correct Syntax with the double quotes. Which was causing the error.
I have updated the post, so if you go back and copy and paste the code it will not work as expected.
I received an error message “The following syntax error occurred during parsing: Invalid token, Line 3, Offset 10, ‘.” when creating the Data Last Refreshed measure (error shown at the link below). I replaced the first quote with a straight quote and it worked fine. Thanks.
https://drive.google.com/file/d/1n4Z3ojhpIqspJbcs-dzyeV44ZMkDMwfn/view?usp=sharing
Awesome, glad you got it working
Howdy,
Re:
>Thanks for the comment, I did create another blog post, where you are able to put in when daylight savings starts and >ends. And it will automatically make the change for you
where is that other blog post that addresses daylight savings time?
I looked but could not locate it.
Thanks !
Hi there, you can find it here:
https://www.fourmoo.com/2017/10/10/using-power-bi-to-ensure-daylight-savings-dates-and-times-change-dynamically/
Thanks for the blog post URL !
I love this but I am getting a time that is 7 hours of ahead of where I live Vancouver Canada. I tried editing your code but it did not work can you please help me. This is what I put and regardless of what number it seems I put it is always 7 hours ahead. In my report on the desktop the time is correct but once it shoots to power bi online service the time changes to 7 hours ahead.
let
TodaysDate = DateTime.From(DateTimeZone.SwitchZone(DateTimeZone.FixedLocalNow(),(-8))),
#”Converted to Table” = #table(1, {{TodaysDate}}),
#”Renamed Columns” = Table.RenameColumns(#”Converted to Table”,{{“Column1”, “Last Refresh Date Time”}}),
#”Changed Type” = Table.TransformColumnTypes(#”Renamed Columns”,{{“Last Refresh Date Time”, type datetime}})
in
#”Changed Type”
Hi there I have found that this often works better with the code below
let
TodaysDate = DateTime.From(DateTimeZone.FixedLocalNow()+ #duration(0,-7,0,0))),
#"Converted to Table" = #table(1, {{TodaysDate}}),
#"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", “Last Refresh Date Time”}}),
#"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Last Refresh Date Time", type datetime}})
in
#"Changed Type"
Fantastic thank you!
Thanks a lot, this is really helpful when your query is connected to a database.
When you are querying an Excel-File however, the last “refresh” would refer to the “modified date” of the file.
I was having trouble with getting this information, as the “modified date” happens to be in Date Format “en-us” (mm.dd.yyyy), whereas the dates in the content of the file, are stored in “german”.
As the locale can be set only for the pbix.file, always one of the dates will result in an error.
Any ideas on how to achieve this? Thank you very much in advance and looking forward to hearing from you.
Best regards
Frank
Hi Frank, thanks for the message.
Would it be possible to send a sample of the dates where one works and one fails?
I could then assist at finding you a solution.
Regards
Gilbert
Hi Gilbert, unfortunately this is not possible as the document is stored in our companies MS TEAMS.
When trying to determine the last-refresh and last-file-update for a document, stored in the file-system or OneDrive, it worked quite well. So I am guessing that it is a MS TEAMS specific problem. If you have the chance to read any file from MS TEAMS, just try to get both dates calculated. If you can do it, the problem might be with our configuration.
Anyway, thanks again for the great tipp and best regards.
Frank
Hi Frank,
I am not sure if you know but all the documents that are stored in MS Teams, are actually stored in SharePoint Online, which is stored in OneDrive.
With the above being said, there is a way to view the data either via SharePoint or via OneDrive, if you sync the files locally.
Let me know if you need some assistance.
Hi Gilbert, yes I know. I have tried it with another Teams-Channel, respectively another SharePoint folder, and it worked. Still do not have a clue, what caused the error in the other folder.
Anyway, thanks again and all the best for you.
Best regards
Frank
Glad that you got it working and for letting me know.
Hi,
I used this method to make a Card visualization in my report showing the last dataset refresh date and time, and it works well when I have the report opened in my Power BI Desktop. The problem is, when I publish the report into Power BI Service as a shared report, the Card visualization does not show the correct dataset refresh date. I have scheduled the dataset refreshes 4 times a day and when looking at the datasets, there is no problem with the refresh, but the refresh date and time in the report are not correct. In the report it shows the last time I refreshed the data in Power BI Desktop.
My dataset uses D365 CRM data.
Any ideas?
Hi Jenni,
I am wondering, did you add this table in the Power Query Editor?
If you did when ever it refreshes the data, it should refresh all the tables.
Great Post.
I have added the code in Power Query and I am getting results as expected but refresh time is still my system time even after adding +10 to the time.
Code:
TodaysDate = DateTime.From(DateTimeZone.SwitchZone(DateTimeZone.FixedLocalNow(),10)),
#”Converted to Table” = #table(1, {{TodaysDate}}),
#”Renamed Columns” = Table.RenameColumns(#”Converted to Table”,{{“Column1”, “Last Refresh Date Time”}}),
#”Changed Type” = Table.TransformColumnTypes(#”Renamed Columns”,{{“Last Refresh Date Time”, type datetime}})
in
#”Changed Type”
For testing I have added 10 to the code it didn’t work for me. In fact I have a requirement to add 5 hours 30 minutes to GMT.
Please help..
Hi there thanks for the comment.
And I actually found a better way to get this done by using the #duration function.
This code below should work for you
let
TodaysDate = DateTime.From(DateTimeZone.FixedLocalNow() + #duration(0,5,30,0)),
#"Converted to Table" = #table(1, {{TodaysDate}}),
#"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Last Refresh Date Time"}}),
#"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Last Refresh Date Time", type datetime}})
in
#"Changed Type"
Thank you this worked perfectly for me after spending an hour researching the quickest, easiest way, this saved me a lot of time.
It is a pleasure, glad it helped you save some time and solve your challenge.
Hi Gilbert,
I need to display on report Dataset last refresh time. Is it possible please confirm.
Regards
Krishna M
Hi there
Yes this can be done, which was part of this blog post?
This shows the expected date in power BI desktop but it change in power BI service.
Which is strange.
Hi there
What you can do is to then change the Refresh date by adding the
+ #duration(0,8,0,0)
which would then add 8 hours to the date. This is because the Power BI Service servers all run on the UTC Timezone Power BI – Did you know ALL Power BI Services Servers are in UTC? Now how to handle it for Dates & TimesDo you know of any way to get the last refresh date/time auto posted to a Teams Channel?
Hi Anthony I am not aware currently if this is possible.
Hi there, I’m having the same issue as a few people mentioned above.
Whenever I publish the report through PowerBI desktop, the last refresh date is updated correctly, but if I rely on the automated refresh settings of PowerBi online, the date does not update accordingly.
Any ideas on how to reflect the automated updates rather than just the manuals? I guess this defeats the purpose of an automated refresh schedule 🙂
Hi Mariano, thanks for the comment.
Based on the blog post it does work when the dataset is refreshed via the scheduled refresh.
The one thing to note is that you also have to interact with the report for the latest values to be updated.