Smart Systems for Home

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

Power Query DateTimeZone.FixedUtcNow Function Guide

· 5 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

The DateTimeZone.FixedUtcNow function in Power Query M language is a specialized utility designed to capture the current Coordinated Universal Time (UTC) at the exact moment a query begins execution. Unlike the standard DateTimeZone.UtcNow, which returns the time when the specific step is evaluated, FixedUtcNow ensures that every reference to this value within a single query refresh cycle remains identical. This consistency is critical for logging, auditing, and ensuring that calculations based on "current time" do not drift during complex data transformations.

What You'll Need

  • A Windows computer with Microsoft Excel or Power BI Desktop installed.
  • Basic familiarity with the Power Query Editor interface.
  • An understanding of how to access the Advanced Editor in Power Query.

Step-by-Step

  1. Open the Power Query Editor: Launch your data source connection. In Excel, go to the Data tab and select Get Data. In Power BI, click Transform Data from the Home ribbon. This opens the Power Query Editor window where you will build your logic.
  2. Create a Blank Query: To test the function effectively without existing data constraints, create a new blank query. In the Home tab of the editor, click New Source > Blank Query. This gives you a clean slate to write custom M code.
  3. Access the Advanced Editor: With the blank query selected, look for the View tab or the Home tab depending on your version. Click on Advanced Editor. This opens a text-based view of the underlying M code, allowing you to manually input functions rather than relying solely on UI buttons.
  4. Input the FixedUtcNow Code: Replace the default code in the Advanced Editor with a simple let expression. Type the following: let CurrentTime = DateTimeZone.FixedUtcNow() in CurrentTime. Note that the function requires parentheses even though it takes no arguments.
  5. Execute the Query: Click Done to close the Advanced Editor. The preview pane should now display a single cell containing a datetimezone value, such as 2023-10-27T14:30:00Z. This confirms the function executed successfully and returned the UTC timestamp fixed at the start of this specific refresh.
  6. Verify Consistency in Multi-Step Queries: To see the true power of this function, add another step. After the initial line, add AnotherTime = DateTimeZone.FixedUtcNow(). When you inspect the results, both variables will hold the exact same timestamp down to the millisecond, proving they were captured simultaneously at the query's inception.

Common Mistakes

The most frequent error is confusing DateTimeZone.FixedUtcNow with DateTimeZone.UtcNow. While both return UTC times, UtcNow evaluates dynamically. If you use UtcNow in two different steps of a long-running query, the second step might show a time several seconds later than the first. This discrepancy can cause bugs in logic that compares timestamps across steps. Always use FixedUtcNow when you need a single, immutable reference point for the entire query duration.

Another common mistake is forgetting the parentheses. Writing DateTimeZone.FixedUtcNow without the () at the end will result in an error because Power Query expects a function call, not just a function name reference. Additionally, users sometimes attempt to pass parameters to this function, but it accepts none; any argument provided will trigger a syntax error.

Tips

Use DateTimeZone.FixedUtcNow as a primary key component for audit tables. By capturing the exact start time of a refresh, you can uniquely identify each batch of processed data. Combine it with other fixed values like DateTime.LocalNow if you need to record both local and server-side timestamps consistently throughout a transformation pipeline.

If you are working in a shared environment where queries run on servers (like Power BI Service), remember that the time reflects the server's clock, not your local machine. Ensure your server infrastructure is synchronized via NTP (Network Time Protocol) to prevent skew between different data gateways or processing nodes. This function relies entirely on the system clock of the engine executing the M code.

Troubleshooting

If you receive an error stating that the name 'DateTimeZone.FixedUtcNow' isn't recognized, check your spelling carefully. M language is case-sensitive. Ensure you have typed DateTimeZone with capital D and T, and FixedUtcNow with capitals F, U, T, C, and N. A typo here is the most likely cause of recognition errors.

If the output shows a date far in the past or future, verify the system time on the machine running Power Query. Since this function pulls directly from the operating system's clock, incorrect local settings will propagate into your data. In corporate environments, contact IT if the server time appears skewed, as you may lack permissions to adjust the OS clock yourself.

If the value changes unexpectedly between steps despite using FixedUtcNow, ensure you are not inadvertently calling DateTimeZone.UtcNow elsewhere in the query. Review all steps for mixed usage. Also, confirm that you are not refreshing the query multiple times rapidly; each manual refresh triggers a new evaluation of FixedUtcNow, so comparing results across separate refreshes will naturally show different times.

Frequently Asked Questions

Does DateTimeZone.FixedUtcNow account for daylight saving time?

No, it strictly returns Coordinated Universal Time (UTC). It does not apply local timezone offsets or daylight saving adjustments. If you need local time, you must convert the UTC result using DateTimeZone.ToLocal or specify a target zone with DateTimeZone.SwitchZone.

Can I use this function in a calculated column in Excel?

No, DateTimeZone.FixedUtcNow is part of the Power Query M language. It can only be used within the Power Query Editor steps. Once the data is loaded into Excel or Power BI, you cannot use this specific function in DAX or Excel formulas.

Why would I choose FixedUtcNow over DateTime.LocalNow?

Choose FixedUtcNow for consistency and global standardization. DateTime.LocalNow depends on the user's machine settings and can vary if the query runs on different machines. FixedUtcNow provides a uniform reference point regardless of where the query executes, making it ideal for backend processes and logs.

Is there a performance cost to using this function?

The performance impact is negligible. Retrieving the system clock is an extremely fast operation. However, calling it repeatedly in row-level contexts (if possible through certain workarounds) is inefficient. Best practice is to call it once in a variable definition at the top of your query and reuse that variable throughout.

How do I format the output to remove milliseconds?

You can wrap the function in formatting tools. For example, use DateTime.ToText(DateTime.Date(DateTimeZone.FixedUtcNow()), "yyyy-MM-dd") to get just the date string. Alternatively, you can subtract the time portion or use DateTime.RemoveMilliseconds if available in your context, though typically you cast to Date or Text as needed.