cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
danextian
Community Champion
Community Champion

DateTimeZone.UtcNow() not working properly in Power BI Service

I have a report that is scheduled to refresh once daily and I need to show the users when the report's dataset was last refreshed.

 

I understand that refreshing a query via service with a DateTime.LocalNow() formula will return the server's timezone instead of the report author's/dataset owner's. Instead, I'm using DateTimeZone.UtcNow() then convert it to my timezone ( +8 ) using DateTimeZone.SwitchZone.  Like DateTime.LocalNow(),  DateTimeZone.UtcNow() works fine when refreshed via desktop but is showing a time 8 hours late than than my current time when refreshed in the service. For example, I refreshed the data set 12 noon my time but the report is showing 4 am instead. 

 

Please let me know what I am missing. 

Did I answer your question? Mark my post as a solution!
"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
www.linkedin.com/in/danebelarminocpa
1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@danextian,

 

Power BI service shows the current date and time in UTC. To solve this issue, you may try the following ways:

  1. Create a measure := Now() + timezoneHours / 24
  2. Create Custom Column in Query Editor: Formula= DateTimeZone.SwitchZone(DateTimeZone.LocalNow(),timezoneHours,0)
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-chuncz-msft
Community Support
Community Support

@danextian,

 

Power BI service shows the current date and time in UTC. To solve this issue, you may try the following ways:

  1. Create a measure := Now() + timezoneHours / 24
  2. Create Custom Column in Query Editor: Formula= DateTimeZone.SwitchZone(DateTimeZone.LocalNow(),timezoneHours,0)
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

 DateTimeZone.SwitchZone(DateTimeZone.LocalNow(),timezoneHours,0) works. Thanks for this. 

 

By the way, would you know what timeonze DateTimeZone.UtcNow() is using?

Did I answer your question? Mark my post as a solution!
"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
www.linkedin.com/in/danebelarminocpa

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Power BI December 2021 Update_carousel 768x460.jpg

Check it Out!

Click here to read more about the December 2021 Updates!

Jan 2022 Dev Camp 768x460 copy.png

Power BI Dev Camp- January 27th, 2022

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors