Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query DateTime.LocalNow: How to Use Timestamps

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

DateTime.LocalNow() is a Power Query function that returns the current date and time on the machine running the refresh, as a single datetime value. It is the quickest way to stamp a query with "last updated" information, but it comes with a catch that trips up most people: its value is volatile, so it can behave differently depending on where the query refreshes and whether Power Query decides to evaluate it more than once. Used deliberately, it is a reliable way to record when data was loaded. Used casually, it can produce blank results, wrong time zones, or values that never update.

What You'll Need

  • Power Query Editor open in Excel, Power BI Desktop, or the Power Query preview in Fabric Dataflows, or a dataset that refreshes in the Power BI service.
  • An existing query you want to stamp, or a blank query you can build with the Advanced Editor.
  • Basic familiarity with the formula bar and with the Power Query M language (nothing beyond a single function call is required here).
  • A decided refresh strategy, because LocalNow depends on where the refresh runs. On a laptop it uses your laptop's clock; in the cloud service it uses the service's clock.

Step-by-Step

  1. Decide what kind of value you actually need. DateTime.LocalNow() returns a datetime (date and time together). If you only need the date, wrap it in DateTime.Date(DateTime.LocalNow()). If you only need the time, use DateTime.Time(DateTime.LocalNow()). Choosing up front avoids reformatting later.
  2. Open the Power Query Editor. In Excel: Data > Get Data > Launch Power Query Editor (or right-click a query in the Queries pane and choose Edit). In Power BI Desktop: Home > Transform data. The Power Query pane layout differs between the two hosts, and labels can differ slightly by version and region, so treat the menu names here as a close guide rather than exact wording.
  3. Create a blank query or pick the target query. For a timestamp added to an existing table, select that query in the Queries pane. For a standalone "last refreshed" value you can reference elsewhere, use Home > New Source > Blank Query.
  4. Open the Advanced Editor. Right-click the query and choose Advanced Editor, or use Home > Advanced Editor. You will see a let block ending in an in clause. This is where you add the function call, which is often simpler and more predictable than hunting for a ribbon button.
  5. Write the call. The simplest version is a one-line query: let Source = DateTime.LocalNow() in Source. This produces a single-cell table value you can turn into a table if you want it to display consistently. To add it to an existing table instead, add a step near the end such as AddedStamp = Table.AddColumn(PreviousStep, "LoadedAt", each DateTime.LocalNow()) and end with in AddedStamp.
  6. Check the data type. If the query returns a bare value rather than a column, the Power Query Editor may show a scalar rather than a table. Right-click the result and use the option to convert to table if you need the value to land in a worksheet or model. For a column, confirm the icon next to the column header shows date/time, not text.
  7. Close and load. Use Home > Close & Load (Excel) or Close & Apply (Power BI Desktop). The value is evaluated when the query refreshes, not continuously, so the stamp reflects refresh time, not clock time.
  8. Test with a refresh, not a preview. The Power Query Editor preview shows a value computed at preview time. Refresh the query or dataset and confirm the stored value changes. This is the only meaningful test of whether the function is wired correctly.
  9. Confirm the time zone assumption. DateTime.LocalNow() returns the local time of the machine performing the refresh. If your report is refreshed in a cloud service, that is the service's configured time zone, which is often UTC. Compare against DateTime.UtcNow() and pick the one that matches what your audience expects.

Common Mistakes

  • Assuming it updates live. The value is fixed at refresh. A workbook left open on screen all day still shows the time of the last refresh, not the current time. There is no formula-style recalculation in Power Query.
  • Mixing local and UTC without noticing. Values stamped on a desktop machine and values stamped by a cloud refresh can differ by hours. If the dataset is refreshed in both places, the timestamps are not comparable unless you standardise on DateTime.UtcNow().
  • Expecting a stable single value inside a row-by-row step. When used inside an each expression, the function is called per row. Power Query usually folds this to one value for a single refresh, but folding is not guaranteed, and a step that is evaluated separately can yield slightly different times. If a single consistent stamp matters, compute it once as its own step and reference that step in the column expression.
  • Forgetting it cannot be used in calculated columns of the data model. DateTime.LocalNow() is a Power Query function, not a DAX function. In a Power BI model the equivalent is NOW() (local time of the viewer's session) or UTCNOW(). These are different functions with different behaviour, so do not swap one for the other and expect identical output.
  • Using it to decide whether data is stale. A refresh timestamp tells you when the query ran, not whether the upstream source had new data. Couple it with a source-side audit column if freshness matters.
  • Typing the name wrongly. M is case-sensitive and uses a dot, not an underscore. Datetime.localnow() or DateTime_LocalNow() will fail to evaluate.

Tips

  • Store the stamp as its own step and reference it, so every column in the same refresh shares one value.
  • Truncate if you only need a date or hour: DateTime.Date(DateTime.LocalNow()) or DateTime.From(DateTime.ToText(DateTime.LocalNow(), "yyyy-MM-dd HH:00")). Rounding makes reports less jittery when refreshes are frequent.
  • Add a fixed-offset version if your audience is in one time zone but the refresh runs in another. Convert with DateTimeZone functions rather than assuming LocalNow will match.
  • Use it in combination with a source-controlled "as of" date when you need to prove which snapshot a report represents.

Troubleshooting

If the query returns an error mentioning that the name is not recognised, recheck spelling and capitalisation inside the Advanced Editor. If the value does not change after a refresh, check whether the query was actually refreshed rather than reopened, and confirm the query is not set to load from a cached preview. If the displayed time is wrong, the machine or service clock and time zone are the cause; compare LocalNow with UtcNow in a temporary query to see the offset. If the timestamp appears as text, apply a data type change to date/time. If a scheduled refresh fails after you add the function, some data gateways and older connectors restrict volatile functions; test the same query without it to isolate the cause.

Frequently Asked Questions

Does DateTime.LocalNow() update automatically?

No. It is evaluated when the query refreshes, and the value stays fixed until the next refresh.

What is the difference between DateTime.LocalNow() and DateTime.UtcNow()?

LocalNow returns the time on the machine performing the refresh. UtcNow always returns UTC, regardless of the machine's time zone.

Can I use it in a DAX measure?

No. It is a Power Query M function. In DAX, use NOW() or UTCNOW() instead, which behave differently and evaluate at query time.

Why does the time change between rows in my table?

The function is called inside a row-level expression. Compute it once in its own step and reference that step to get one consistent value.

Is the time zone of a cloud refresh the same as mine?

Not necessarily. Cloud refreshes often run in UTC or the region set for the capacity, so the stamp may not match your local clock.