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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
ShaelynFrench
Helper I
Helper I

Problem with DateTime.LocalNow() in the service

Hi,

 

I have a date table that uses a fixed date as the start date of the date Table and Date.From(DateTime.LocalNow()) as the end date. So the date table should always be updated to go through today. It works great in Desktop but as soon as I publish the report, it doesn't work in the Service. The end date stays the date that I published the report and isn't updating. Any advice? Is there any way to get it to work as expected? Thanks!

4 REPLIES 4
edhans
Super User
Super User

You have to refresh the report. DateTime.LocalNow() only changes on a refresh. Think of it like the TODAY() function in Excel. It doesn't change until there is a recalculation necessary. If you just put that in cell A1 of an spreadsheet and leave Excel open, it will never change.




Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

@edhans oh, yeah, sorry, I've obviously tried refreshing the dataset, refreshing the visual and I tried clearing the browser cache which is the only suggestion I could find online. None of those worked.

Does this happen for days? DateTime.LocalNow() reports the server time, not your time, and the server is on UTC. So it will be several hours off and appear not to change. To force it to be your time, try this code, where -8 is my timezone offset, so adjust for your offset.

 

DateTime.Date(DateTimeZone.SwitchZone(DateTimeZone.LocalNow(),-8))

I go into more depth on this in this article. And it has worked for years.

Add a Refresh Time Stamp To Your Power BI Reports — ehansalytics

 

Otherwise, you'll need to post the code for the query you are using as something else is preventing that code from being read/used.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Ok, thank you. Yeah, it's not just a few hours off, I published the report on 2/10/2023 and then tried the refresh on 3/10/2023 and it was sticking with the 2/10 date. I re-published the report on 3/10 and it is still stuck on 3/10 when I refreshed today (3/14). I am using a rather complicated M code for the date table, so it must be something in that code (it is way beyond me, I just copied it from online). I will try a more simple date table and see if that works.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors