Power Query DateTime.FixedLocalNow: How to Use It
In this article
DateTime.FixedLocalNow returns the current local date and time as a fixed value that stays the same for the entire duration of a query evaluation, unlike DateTime.LocalNow which can return a different value each time it is called. Use it when you need a stable timestamp for a single query run, such as stamping a refresh time or calculating age from a single reference point.
What You'll Need
- Power BI Desktop, Excel with Power Query, or another host that supports Power Query (such as Analysis Services or Dataflows). The function is part of the standard M library and requires no add-ins.
- A query open in the Power Query Editor where you can add a custom column or step.
- Basic familiarity with the Power Query Editor interface and the M formula language.
Step-by-Step
- Open the Power Query Editor. In Excel, go to the Data tab and select Get Data > Launch Power Query Editor (or edit an existing query). In Power BI Desktop, select Transform Data from the Home ribbon. Menu labels can differ slightly by version, host application, and region.
- Choose where to apply the function. You can add it as a custom column, use it in a calculated step, or create a standalone query. For a timestamp column, select Add Column > Custom Column. For a single value used elsewhere, you can add a step in the Advanced Editor or create a blank query and enter the expression in the formula bar.
- Enter the expression. In the Custom Column dialog, name the column (for example, RefreshTimestamp) and enter the formula:
DateTime.FixedLocalNow(). The function takes no arguments, so the parentheses are empty. - Confirm the data type. After adding the column, Power Query may infer the type as datetime or any. Click the type icon in the column header and select Date/Time to ensure it is treated as a datetime value. This matters for later calculations such as durations or filtering.
- Check the result. The column will show the local date and time at the moment the query was evaluated. Because it is fixed, every row in that query run gets the same value, even if the refresh takes several minutes.
- Use it in calculations. To compute an age or elapsed time, subtract a date column from the fixed timestamp, for example:
DateTime.FixedLocalNow() - [OrderDate]. The result is a duration. You can then extract days with Duration.Days or format it as needed. - Apply and close. Select Close & Load (Excel) or Close & Apply (Power BI) to commit the query. On the next refresh, the function recalculates once and the new fixed value applies to the whole run.
Common Mistakes
- Confusing FixedLocalNow with LocalNow. DateTime.LocalNow can return a slightly different value each time it is called within a query, which can cause inconsistent timestamps across rows. FixedLocalNow guarantees one value per evaluation.
- Expecting the value to update automatically. The timestamp only changes when the query refreshes. It does not tick in real time, and it is not a live clock.
- Forgetting the time zone. FixedLocalNow returns the local time of the machine or service running the query. In scheduled refreshes, that is the refresh server's local time, which may differ from your own. If you need UTC, use DateTime.FixedUtcNow instead.
- Using it in a calculated column in the data model. This is a Power Query function, not a DAX function. In DAX, use NOW() or TODAY(), and be aware those recalculate on each visual refresh rather than being fixed per query run.
- Assuming it works in every host. The function is part of the standard library, but some older or limited Power Query hosts may not expose it. If the formula bar rejects it, check that your host supports the full M library.
Tips
- Use DateTime.FixedLocalNow when you need a single reference point for the whole query, such as calculating the age of all records as of refresh time.
- If your report is used across time zones, store the UTC value with DateTime.FixedUtcNow and convert for display, rather than relying on local time.
- Combine with DateTime.Date to get just the date portion:
DateTime.Date(DateTime.FixedLocalNow()). - For auditing, add the timestamp as a column before other transformations so it reflects the start of the refresh rather than the end.
- Remember that the value is fixed per query evaluation, not per session. Each refresh produces a new fixed value.
Troubleshooting
If the function returns an error, first check the spelling and parentheses: it must be DateTime.FixedLocalNow() with no arguments. If the column shows a date but not a time, verify the data type is set to Date/Time, not Date. If the value looks wrong, confirm the local time zone of the machine or service running the refresh; scheduled refreshes use the server's time zone. If the function is not recognized, update your Power Query host to a current version. If calculations using the timestamp give unexpected durations, ensure both operands are datetime values and not text. When a refresh fails after adding the step, use the Applied Steps pane to inspect the step and correct the formula; the error message usually points to the exact expression.
Frequently Asked Questions
What is the difference between DateTime.FixedLocalNow and DateTime.LocalNow?
DateTime.LocalNow can return a different value each time it is evaluated within a query, while DateTime.FixedLocalNow returns one value that stays constant for the entire query evaluation. Use FixedLocalNow when consistency across rows matters.
Does DateTime.FixedLocalNow update in real time?
No. It captures the local date and time at the moment the query is evaluated and does not change until the next refresh.
Can I use DateTime.FixedLocalNow in DAX?
No, it is a Power Query M function. In DAX, use NOW() or TODAY(), but note those are not fixed per query run in the same way.
Which time zone does DateTime.FixedLocalNow use?
It uses the local time zone of the environment running the query. For scheduled refreshes, that is typically the refresh server or gateway machine, not your desktop.
How do I get UTC instead of local time?
Use DateTime.FixedUtcNow, which returns a fixed UTC timestamp for the query evaluation.
Why does my timestamp column show the same value for every row?
That is expected. FixedLocalNow returns a single value per query run, so every row receives that same timestamp.