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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Lexixl
Frequent Visitor

How to Create an Refresh Failed message in the Text Box in Power BI Desktop

Hi

I have a report connect to the Azure Sql Database. And I schudle the refresh time in Power BI Service. However, sometimes the scheduled refresh failed and the report can't be refreshed to the most recent data.

For now, our customer wants to see an error message like 'the data is not to date' in the report when the refresh failed. But when the report refresh successfully, this message will be hidden. 

 

I'm trying to create the refresh time table depends on the local time and want to add an column to show whether the local time is in the refresh time span (From 8:30 am to 12:30 pm) as below: 

Lexixl_1-1628740032446.png

 

Lexixl_0-1628739964501.png

But it gives me an error and I'm not sure it's a good way to solve this issue.

 

Is it possible to do as my customer expect?

 

Thank you so much for your help.

1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey @Lexixl , from the screenshot you provided it seems you are using DAX function and syntax to calculate the column you want inside Power Query. Either you change to M functions / M syntax (M is the language you can use together with Power Query, or you use DAX to create a calculated column or measure.

 

Nevertheless, I tend to use a mixture. I use Power Query (M) to create a table that just contains a single row and a single column.

This is the M code to create this table:

 

let
    Source = Table.FromRecords({[RefreshDateTime = DateTime.LocalNow()]}),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"RefreshDateTime", type datetime}})
in
    #"Changed Type"

 

Just Copy/Paste the code to a blank query using the Advanced Editor inside Power Query.

Whenever the data will be refreshed successfully this table contains a datetime value that corresponds to the latest refresh. Please be aware that I name the table "RefreshDateTime"

 

Then you can use DAX code to create a measure similar to this:

 

CurrentOrNot = 
var LatestRefreshDateTime = MAX( 'RefreshDateTime'[RefreshDateTime] )
var CurrentDateTime = NOW()
var Difference = DATEDIFF( LatestRefreshDateTime , CurrentDateTime , MINUTE )
return
IF( Difference < 60 , "current" , "not current")

 

 

Hopefully, this provides some ideas on how to tackle your challenge.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

2 REPLIES 2
TomMartens
Super User
Super User

Hey @Lexixl , from the screenshot you provided it seems you are using DAX function and syntax to calculate the column you want inside Power Query. Either you change to M functions / M syntax (M is the language you can use together with Power Query, or you use DAX to create a calculated column or measure.

 

Nevertheless, I tend to use a mixture. I use Power Query (M) to create a table that just contains a single row and a single column.

This is the M code to create this table:

 

let
    Source = Table.FromRecords({[RefreshDateTime = DateTime.LocalNow()]}),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"RefreshDateTime", type datetime}})
in
    #"Changed Type"

 

Just Copy/Paste the code to a blank query using the Advanced Editor inside Power Query.

Whenever the data will be refreshed successfully this table contains a datetime value that corresponds to the latest refresh. Please be aware that I name the table "RefreshDateTime"

 

Then you can use DAX code to create a measure similar to this:

 

CurrentOrNot = 
var LatestRefreshDateTime = MAX( 'RefreshDateTime'[RefreshDateTime] )
var CurrentDateTime = NOW()
var Difference = DATEDIFF( LatestRefreshDateTime , CurrentDateTime , MINUTE )
return
IF( Difference < 60 , "current" , "not current")

 

 

Hopefully, this provides some ideas on how to tackle your challenge.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
AllisonKennedy
Super User
Super User

@Lexixl I'm a bit confused on what your date table date is representing? Would it be sufficient to calculate the last Refresh time and compare that to current time? You will need to use DAX for this to calculate UTCNOW and compare that to the refresh time in UTC. Display Last Refreshed Date in Power BI - The Excelguru BlogThe Excelguru Blog

 

Then use DAX to create the error message, or even just display the last refresh time. Would that work?


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.