DateTimeZone.SwitchZone: Power Query Guide and Usage
In this article
The DateTimeZone.SwitchZone function in Power Query is used to convert a datetimezone value from one time zone offset to another without changing the actual moment in time. Unlike functions that simply add or subtract hours, SwitchZone adjusts both the displayed time and the offset simultaneously, ensuring that the underlying UTC timestamp remains identical while the local representation changes to reflect a different region.
What You'll Need
- Microsoft Excel or Power BI Desktop with Power Query installed.
- A column with the
DateTimeZonedata type (indicated by the clock and globe icon in the column header). - Knowledge of the target time zone offset (e.g., -5 for Eastern Standard Time or +1 for Central European Time).
Step-by-Step
- Load Your Data: Open Power Query Editor by selecting
Data > Get Datain Excel orTransform Datain Power BI. Ensure your date column is correctly typed asDateTimeZone. If it is currentlyDateTimeorText, right-click the column header, selectChange Type, and chooseDateTimeZone. - Create a Custom Column: Navigate to the
Add Columntab on the top ribbon and selectCustom Column. This allows you to write the M formula manually rather than relying on the limited GUI options for time zone shifting. - Enter the Function: In the Custom Column dialog box, give your new column a name (e.g., "Local Time"). In the formula box, enter the following syntax:
DateTimeZone.SwitchZone([YourColumnName], targetOffset). Replace[YourColumnName]with the name of your source column andtargetOffsetwith a number representing the hours from UTC. For example, to move a UTC time to New York (EST), useDateTimeZone.SwitchZone([Timestamp], -5). - Handle Dynamic Offsets (Optional): If your target offset is stored in another column, replace the hardcoded number with the column reference:
DateTimeZone.SwitchZone([Timestamp], [OffsetColumn]). - Verify the Result: Look at the resulting column. You should see that the hour has shifted and the offset at the end of the timestamp (e.g., +00:00 to -05:00) has updated accordingly. The total time elapsed since the Unix epoch remains the same.
- Convert to Local DateTime: Often, you only need the local time without the offset suffix. To achieve this, right-click the new column, select
Change Type, and chooseDate/Time. This strips the zone information while keeping the shifted local hour.
Common Mistakes
One of the most frequent errors is confusing DateTimeZone.SwitchZone with DateTimeZone.ToUtc or simple addition. If you use a custom column to add hours (e.g., [Time] + #duration(0, -5, 0, 0)), you are changing the actual point in time, but the offset remains the same. This creates a "false" timestamp that is mathematically incorrect. SwitchZone is the only way to change the perspective of the time zone while maintaining the integrity of the moment.
Another common mistake is applying the function to a DateTime column instead of a DateTimeZone column. The function will return an error if the input is not explicitly a datetimezone type. Always check your data types in the column header before applying the formula. If your data arrives as a simple date and time without an offset, you must first use DateTimeZone.From to assign it a starting zone before you can switch it to another.
Users also frequently forget that offsets are numerical. Entering "-5:00" as a string will cause a formula error. The second argument of the function must be a number (decimal or integer). If you have a string like "-05:00", you must first convert that string into a numeric value of hours before passing it into the SwitchZone function.
Tips
To make your reports more flexible, avoid hardcoding the offset number inside the formula. Instead, create a separate "Settings" table in your data model that contains the current offset for your target region. You can then reference this value in your Power Query formula using a drill-down step. This allows you to update the time zone for the entire report in one place without editing multiple M formulas.
When dealing with Daylight Saving Time (DST), remember that DateTimeZone.SwitchZone does not automatically detect whether a specific date falls within DST. It applies a static offset. To handle DST, you will need to create a conditional column that checks the date range (e.g., if the date is between March and November) and applies either -4 or -5 depending on the result. This logic can be wrapped inside an if...then...else statement surrounding the SwitchZone function.
If you are working with a global dataset, use DateTimeZone.UtcNow() as a starting point to create a "Last Refreshed" timestamp. By combining UtcNow() with SwitchZone, you can display the exact refresh time in the user's local time zone regardless of where the Power BI service (which usually runs in UTC) is hosted.
Troubleshooting
If you encounter an Expression.Error: We cannot convert the value to type DateTimeZone, it means your source column is likely a DateTime or Text type. To fix this, go to the step immediately preceding your custom column and change the type of the source column to DateTimeZone. If the source data lacks offset information, use DateTimeZone.From([Column]) to force it into the correct type first.
If the time is shifting in the wrong direction (e.g., it is adding hours when it should be subtracting), double-check your offset sign. Remember that UTC-5 is west of Greenwich (Americas) and UTC+1 is east (Europe/Africa). A common error is using a positive number for Western hemispheres.
If the formula returns null, check your source data for empty cells. DateTimeZone.SwitchZone cannot process null values. You can wrap your formula in a null check to prevent this: if [Timestamp] = null then null else DateTimeZone.SwitchZone([Timestamp], -5).
Frequently Asked Questions
Does SwitchZone change the UTC time?
No. It only changes the local representation and the offset. The underlying UTC moment remains exactly the same, which is critical for maintaining data integrity across different regions.
How is this different from adding a Duration?
Adding a duration (e.g., + #duration(0, 5, 0, 0)) changes the actual time value but keeps the offset label the same. SwitchZone changes both the time and the label, keeping the point in time constant.
Can I use this to handle Daylight Saving Time automatically?
No, DateTimeZone.SwitchZone accepts a static number. You must implement your own logic using a conditional column or a lookup table to determine which offset to apply based on the date.
What is the maximum offset I can use?
The function supports any valid time zone offset, typically ranging from -12 to +14 hours, depending on the global time zone standards.
Why does my column still show the offset after I use the function?
Because the output of SwitchZone is still a datetimezone type. To remove the offset (e.g., +05:00) and keep only the local date and time, you must change the column type to Date/Time after the conversion step.