Smart Systems for Home

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

Power Query DateTimeZone.RemoveZone Guide

· 8 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Deep Dive: When to Use RemoveZone vs. Other Functions
  5. Tips
  6. Troubleshooting
  7. Frequently Asked Questions

To use the DateTimeZone.RemoveZone function in Power Query, you must apply it to a column containing DateTimeZone values within the Power Query Editor. This function strips the offset information (such as +05:00 or -08:00) from a timestamp, converting it into a standard DateTime format while retaining the local time shown in the original value. This is essential when you need to perform calculations, create time-series visualizations, or merge tables where time zone offsets cause data type mismatches and errors.

What You'll Need

  • Microsoft Excel or Power BI Desktop installed on your computer.
  • A data source containing at least one column with the 'DateTimeZone' data type (common in web APIs, SQL databases with offset support, or ISO 8601 formatted text).
  • Basic familiarity with the Power Query Editor interface and the concept of M language formulas.

Step-by-Step

  1. Load your data into Power Query: Open Excel or Power BI. If using Excel, go to the Data tab, select Get Data, and choose your source. If using Power BI, click Get Data and select your file or database. Once the data is loaded, click 'Transform Data' to open the Power Query Editor window.
  2. Verify the Data Type: Look at the column you intend to modify. Check the icon to the left of the column header. For this function to work, the icon must represent a DateTimeZone type (usually indicated by a small calendar and clock icon with a zone offset symbol). If the column is currently set to 'Text' or 'Date/Time', you must first convert it by clicking the icon and selecting 'DateTimeZone'. If the data looks like '2023-10-01T12:00:00+02:00', it is likely a text string that needs this conversion first.
  3. Open the Custom Column Dialog: Instead of overwriting your original data immediately, it is best practice to create a new column. This allows you to audit the results against the original values. Navigate to the 'Add Column' tab on the top ribbon and click on 'Custom Column'.
  4. Enter the Function Syntax: A dialog box will appear. In the 'New column name' field, type a descriptive name like 'Local DateTime'. In the 'Custom column formula' box, type the following formula: = DateTimeZone.RemoveZone([YourColumnName]). Replace [YourColumnName] by double-clicking the actual name of your column from the list on the right side of the dialog box. This ensures you do not have any typos in the column reference.
  5. Apply the Formula: Click 'OK'. A new column will appear at the end of your table. You will notice that the values no longer show the offset (e.g., they change from 2023-10-01 12:00:00 +02:00 to 2023-10-01 12:00:00).
  6. Set the New Column Type: The new column often defaults to a 'General' or 'Any' data type. To ensure it works correctly in your final reports, click the icon next to the new column header and select 'Date/Time'. This is a critical step; without it, Power BI or Excel may treat the column as text, preventing you from using time-based slicers or date hierarchies.
  7. Clean Up: If you no longer need the original DateTimeZone column, right-click the old column header and select 'Remove'. Finally, go to the 'Home' tab and click 'Close & Apply' to load the cleaned data back into your workbook or model.

Common Mistakes

One of the most frequent mistakes is attempting to use DateTimeZone.RemoveZone on a column that is formatted as a standard 'DateTime' or 'Date' type. The function specifically expects a DateTimeZone input. If you try to run it on a column that does not have an offset, Power Query will return an error because there is no zone to remove. Always ensure the input type is explicitly DateTimeZone before applying the function. If your column is currently 'Date/Time', you must first go to the 'Transform' tab and change the type to 'DateTimeZone'.

Another common error involves misunderstanding what the function actually does to the time itself. Users often assume that DateTimeZone.RemoveZone will convert the time to a specific standard, such as UTC. This is incorrect. The function does not perform any mathematical adjustment to the hour or minute; it simply removes the offset portion of the string. If your time is 10:00 AM +05:00, the result will be 10:00 AM. If you actually wanted the UTC equivalent (which would be 5:00 AM), you should use DateTimeZone.ToUtc instead. This distinction is vital for data accuracy in global reporting.

Finally, users often forget to change the data type of the resulting column. Even though the offset is gone, Power Query might still treat the column as a 'Text' or 'Any' type. This prevents you from using time-based filters, such as "is after a certain date", in your final report. Always manually set the type to 'Date/Time' after creating the custom column to ensure the engine recognizes it as a temporal value.

Deep Dive: When to Use RemoveZone vs. Other Functions

Understanding the specific use case for DateTimeZone.RemoveZone requires comparing it to similar temporal functions in the M language. The primary driver for using this function is the removal of metadata rather than the adjustment of values.

Scenario A: Visual Consistency. If you are importing data from multiple regions and you want to show the 'wall clock' time that was recorded at the source, DateTimeZone.RemoveZone is the correct choice. It preserves the local perspective of the data point without shifting the hours. This is useful for logs where the local time of the event is more important than the global UTC time.

Scenario B: Data Normalization. If you are trying to align data from different time zones to a single standard, DateTimeZone.RemoveZone is the wrong choice. In this case, you should first use DateTimeZone.ToUtc to shift all timestamps to the zero-offset standard, and then use DateTimeZone.RemoveZone to strip the +00:00 offset. This provides a clean, uniform 'DateTime' column that is mathematically comparable across all rows.

Scenario C: Time Zone Switching. If you have data in UTC but want to display it in your local business time (e.g., EST), you should use DateTimeZone.SwitchZone first. This function adjusts the actual hour value to the new offset. Once the time has been adjusted to your local hours, you can then use DateTimeZone.RemoveZone to remove the offset and present a clean 'Date/Time' value to the end-user.

Tips

To keep your data model clean, always perform these transformations as early as possible in your Power Query steps. This prevents type mismatch errors when you later try to merge two tables that have different temporal formats. If you are merging a table from a web API (which almost always uses DateTimeZone) with a local Excel table (which usually uses DateTime), the merge will fail unless you strip the zones from the API data first.

If you want to avoid creating a new column and prefer to transform the existing one to save memory, you can use the 'Transform' tab instead of the 'Add Column' tab. However, you will need to write a slightly different M code snippet in the Formula Bar to wrap the existing column reference. For most users, the 'Add Column' method is safer as it provides a backup of the original data in case the transformation goes wrong.

Another efficiency tip is to check for nulls before applying the function. If your dataset is large, applying functions to null values can sometimes slow down the refresh process or create unexpected error rows. Using a conditional column to check if [Column] <> null then DateTimeZone.RemoveZone([Column]) else null can make your query more robust.

Troubleshooting

If you encounter an error saying "Expression.Error: We cannot convert the value... to type DateTimeZone," check your input column immediately. This error almost always means your column is currently formatted as Text or DateTime. Go back to the previous step in your 'Applied Steps' pane and ensure the column type is set to 'DateTimeZone'. If the source data is text, you may need to use DateTimeZone.FromText before you can use the remove zone function.

If the function returns null for certain rows, check the source data. If the original cell in your source (like an Excel sheet or CSV) was empty or contained a non-date string, Power Query will return a null value. You can fix this by using the 'Replace Errors' or 'Replace Values' feature in the Transform tab before applying the RemoveZone function.

If the time appears to be wrong after removing the zone, remember the distinction: DateTimeZone.RemoveZone is a structural change, not a mathematical one. If the time is incorrect for your time zone, you likely need to use DateTimeZone.SwitchZone to adjust the hours to your local time before stripping the zone away. For example, if your data is in UTC and you want it to reflect your local time, switching the zone is the only way to change the hour digit itself.

Frequently Asked Questions

Does this function change the time to UTC?

No. It simply removes the offset information. If the time was 5:00 PM +02:00, the result is 5:00 PM. It does not adjust the hour to 3:00 PM UTC.

Can I use this on a Text column?

Not directly. You must first change the column type to 'DateTimeZone' using the data type selector in the header, otherwise, the function will return an error.

What is the difference between RemoveZone and ToUtc?

DateTimeZone.RemoveZone keeps the local time as is and just hides the offset. DateTimeZone.ToUtc actually changes the hour value to match the Universal Coordinated Time standard.

Why am I getting an error when merging tables?

Merging tables requires identical data types. If one table has 'DateTimeZone' and the other has 'DateTime', the merge will fail. Use RemoveZone on the DateTimeZone column to make them match.

Is this function available in Excel?

Yes, this function is part of the M language used in Power Query, which is available in all modern versions of Excel via the 'Get & Transform Data' feature.

Can I remove the zone without using a Custom Column?

Yes, you can use the 'Transform' tab to apply changes to an existing column, but it requires editing the formula bar directly to ensure the function is applied to the correct column reference.