cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
nleuck_101
Resolver II
Resolver II

Last Refresh date/time from Power Service in Power BI Desktop report

Hello All,

 

Is it possible to get the last refresh date/time on the dataset in the service added to a Power BI desktop report? I was trying to use this article https://excelguru.ca/display-last-refreshed-date-in-power-bi/ but the website for the time api is no longer available.

 

Any help would be greatly appreicated!

 

Thanks,

1 ACCEPTED SOLUTION

Could you just create a custom column in Power Query and use:
DateTime.LocalNow()

#"Added Custom" = Table.AddColumn(#"Changed Type", "LastUpdate", each DateTime.LocalNow())

 

Then format it as DateTime

#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"LastUpdate", type datetime}})

 

This should then show wich time the table was refreshed as it will update the column with current date and time.


M code:

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUUpMSlaK1YlWMkJiGyOxTWDsWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Dummy = _t, Abc = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Dummy", Int64.Type}, {"Abc", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "LastUpdate", each DateTime.LocalNow()),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"LastUpdate", type datetime}})
in
#"Changed Type1"

 

Marius

View solution in original post

12 REPLIES 12
PunchBird
Resolver II
Resolver II

First add a blank query in the Power Query Editor

let
    Source = DateTime.Time(DateTime.LocalNow()) & DateTime.Date(DateTime.LocalNow())
in
    Source

Then add this measure to your model and to visualize it put the measure in a card visual:

Last Refresh =
VAR GetLastRefresh =
    FIRSTDATE ( 'LastRefresh'[LastRefresh] )
RETURN
    "Last refreshed on: " & FORMAT ( GetLastRefresh, "dd mmmm yyyy" ) & " "
        & REPLACE (
            FORMAT ( GetLastRefresh, "HH:mm:ss AMPM" ),
            1,
            2,
            HOUR ( GetLastRefresh ) + 2
        )

Please note time is set to UTC+2 (Daylight Savings Time) or UTC+1 - this will display incorrect in Power BI Desktop but correct in Power BI Service (after refresh in Power BI Service). The last parameter in this Measure (+2) needs to be updated when change to/from Daylight Savings Time.

@PunchBird 

This did not work. I try refreshing the dataset in Power BI Service and the time doesn't change.

@mariussve1  is right, you may need to refresh the report in Power BI service as well after refreshing the dataset. 

In the top right corner in service, when you are in the report, you should se this:

mariussve1_0-1662043756296.png

 

Try push the refrehs button I have ringed out in red. This should work, but maybe some cache issues?

Marius

amitchandak
Super User
Super User

@nleuck_101 , The power query code should work. Which time api is no longer available ?

 

Similar solution -https://askgarth.com/blog/add-the-last-refreshed-date-and-time/



Learn Power BI - Full Course with Dec-2022, with new DAX functions like Window, Index, Offset !!
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Formatted Profit and Loss Statement with empty lines

@amitchandak 

That solution only works when you refresh the report manually. I'm looking to grab the scheduled refresh from the dataset in the service and bring it into the desktop report.

Could you just create a custom column in Power Query and use:
DateTime.LocalNow()

#"Added Custom" = Table.AddColumn(#"Changed Type", "LastUpdate", each DateTime.LocalNow())

 

Then format it as DateTime

#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"LastUpdate", type datetime}})

 

This should then show wich time the table was refreshed as it will update the column with current date and time.


M code:

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUUpMSlaK1YlWMkJiGyOxTWDsWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Dummy = _t, Abc = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Dummy", Int64.Type}, {"Abc", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "LastUpdate", each DateTime.LocalNow()),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"LastUpdate", type datetime}})
in
#"Changed Type1"

 

Marius

I did have to make one change:

#"Added Custom" = Table.AddColumn(#"Changed Type", "LastUpdate", each DateTime.LocalNow() - #duration(0,4,0,0))

@mariussve1 

 

It looks like this just gives me the refresh when I manually refresh the report. Does this give me the refresh from the scheduled refresh on the service?

Yes, this will also update the column when you have a scheduled refresh on the service. The column will get updatet data everytime the table is refreshed.

You might need to adjust it for your timezone, because I think its UTC that is standard in the service. But if you live in UTC+2 then you just add 2 hours:
DateTime.LocalNow() + #duration(0,2,0,0)

Marius

Or do you want to make a own report that grabs all scheduled refresh history from service?
Then you might need to use this rest api:
https://docs.microsoft.com/en-us/rest/api/power-bi/admin/get-refreshables-for-capacity

If you ex use Powert Automate or ADF you can then get all history of refreshes and put it in a table on your datawarehouse or in a csv / excel file.

And then you can use this in your report as source.

Marius

Helpful resources

Announcements
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

Thank you 2022 Review

2022 Monthly Feature Releases

We had a great 2022 with a ton of feature releases to help you drive a data culture.