Power Query DateTimeZone.LocalNow Function: How to Use It
In this article
The DateTimeZone.LocalNow function in Power Query returns the current date and time in your local time zone as a datetimezone value. This is useful for timestamping data imports, tracking when a query ran, or aligning data with local business hours. No installation or setup is required beyond having Power Query available in Excel, Power BI, or other supported platforms.
What You'll Need
- Microsoft Excel 2016 or later (with Power Query enabled)
- Power BI Desktop (any recent version)
- Access to a Windows or macOS system with a configured local time zone
- Basic familiarity with Power Query Editor (M language syntax helpful but not required)
Step-by-Step
- Open your data source in Power Query Editor. In Excel, go to Data > Get Data > From Table/Range or any other source. In Power BI, select Get Data and choose your source.
- Once in the Power Query Editor, locate the Add Column tab on the ribbon at the top.
- Click on Custom Column. A dialog box will appear with fields for New column name and Custom column formula.
- In the New column name field, type a descriptive name such as "Query Run Time" or "Timestamp".
- In the Custom column formula field, type exactly: DateTimeZone.LocalNow(). Do not add spaces before or after the parentheses, and ensure the capitalization is exact.
- Click OK. A new column will appear in your query table with a single value representing the exact moment you clicked OK, in your local time zone with offset (e.g., 2024-05-15T14:32:18-05:00).
- Change the column data type if needed. Right-click the column header, select Change Type > DateTimeZone to ensure it’s recognized correctly.
- Use this column in subsequent steps—for example, filter rows based on time, merge with other timestamped data, or append to a log table.
- Close and Apply to load the data back to your worksheet or Power BI report. Each time you refresh the query, DateTimeZone.LocalNow will update to the current local time at refresh time.
Common Mistakes
- Typing "DateTimeZone.LocalNow" without parentheses—this causes a syntax error because it’s a function call, not a variable.
- Using "DateTime.Now" or "DateTime.LocalNow"—these do not exist; the correct function name includes "DateTimeZone".
- Assuming the time zone is UTC—DateTimeZone.LocalNow always uses your system’s configured local time zone, not UTC or server time.
- Using it in calculated columns in Power BI Model view instead of Query Editor—it only works in Power Query M code, not DAX.
- Expecting it to update in real-time in a report—it updates only on data refresh, not continuously like a live clock.
Tips
- Combine DateTimeZone.LocalNow with DateTimeZone.SwitchZone to convert the timestamp to a different time zone if needed—for example, to standardize global data to UTC.
- Use Text.From(DateTimeZone.LocalNow()) to convert the value to a readable text string for display in reports or logs.
- Store the result in a separate table for audit trails. Create a new query with only DateTimeZone.LocalNow() and append it to a log table each refresh.
- When sharing workbooks or reports, ensure recipients’ systems have correct time zone settings—DateTimeZone.LocalNow reflects the user’s local system time, not the file’s origin.
- For dynamic reporting, use this function in a standalone query and reference it as a parameter, making it easier to manage across multiple queries.
Troubleshooting
- If you see an error saying "Expression.Error: The name 'DateTimeZone.LocalNow' wasn't recognized", check for typos. The function name must be spelled exactly as written, including case.
- If the column shows a blank or null value, your query may have errors earlier in the pipeline. Go to Applied Steps and check for failed transformations.
- If the time is off by several hours, verify your system’s time zone settings in Windows (Settings > Time & Language > Date & Time) or macOS (System Settings > General > Date & Time). Power Query uses the OS time zone.
- If DateTimeZone.LocalNow updates inconsistently across multiple queries in the same file, ensure all queries are set to refresh together. In Excel, go to Data > Queries & Connections > right-click query > Properties > check "Refresh data when opening file" and "Refresh all".
- If you’re using Power BI and the timestamp doesn’t appear in the visual, check that the column is marked as "Do not load"—if so, uncheck it in the Query Settings pane.
- If you’re on a corporate machine with restricted permissions, contact your IT department. Some environments block dynamic functions like this for security reasons.