Smart Systems for Home

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

Power Query DateTimeZone.ToLocal 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.ToLocal function in Power Query converts a datetimezone value to the local time zone of the machine running the query. This is essential when working with global data that includes time zone information and you need to display or analyze times in your local context. No setup is required beyond having a datetimezone column in your data source.

What You'll Need

  • A data source in Power Query that includes a column with datetimezone values (e.g., from APIs, databases, or CSV files with timezone offsets like "2023-10-05T14:30:00+00:00").
  • Power Query Editor open in Excel, Power BI Desktop, or another supported Microsoft tool.
  • Permission to modify queries in your current workbook or report.

Step-by-Step

  1. Open your workbook or report in Excel or Power BI Desktop and navigate to the Power Query Editor by selecting "Transform Data" from the Data tab (Excel) or the Home tab (Power BI).
  2. In the Queries pane on the left, locate and click the query containing your datetimezone column. If you don't see a datetimezone column, ensure your source data includes timestamps with time zone offsets (e.g., ISO 8601 format with +00:00, -05:00, etc.).
  3. Select the column you want to convert to local time. Click on the column header to highlight it. If the column type is not already set to DateTimeZone, right-click the column header, choose "Change Type", then select "DateTimeZone". This ensures the function can operate correctly.
  4. Go to the "Add Column" tab in the ribbon at the top of the Power Query Editor.
  5. In the "DateTime" group, click "To Local". This automatically generates a new column with the formula = DateTimeZone.ToLocal([YourColumnName]).
  6. Review the new column. Each value should now reflect the equivalent time in your system's local time zone. For example, a datetimezone value of "2023-10-05T14:30:00Z" (UTC) will convert to "2023-10-05T09:30:00-05:00" if your system is set to Central Daylight Time.
  7. If you no longer need the original datetimezone column, right-click its header and select "Remove" to clean up your query.
  8. Click "Close & Apply" to load the transformed data back into your workbook or report.

Common Mistakes

  • Applying DateTimeZone.ToLocal to a column that is not of type DateTimeZone — this causes an error. Always verify the column type before applying the function.
  • Assuming the function changes the system's time zone — it does not. It only converts the value based on the machine’s current system time zone setting.
  • Using it on text columns containing date strings without time zone offsets (e.g., "2023-10-05 14:30:00"). These must first be converted to DateTimeZone using DateTimeZone.FromText or similar.
  • Expecting the result to match the time zone of the data source rather than the local machine. The function always uses the machine’s local time zone, not the source’s time zone.

Tips

  • Use DateTimeZone.ToLocal in combination with DateTimeZone.FromText when importing time data from flat files. First parse the text into a datetimezone, then convert to local time.
  • Keep the original datetimezone column for auditing. Converting to local time loses the original offset context, which may be needed for reporting across regions.
  • If you're sharing the file with others in different time zones, note that the converted times will appear differently on their machines. Consider keeping the UTC version as a reference.
  • For consistent results across environments, consider converting to UTC first with DateTimeZone.ToUtc, then to local. This avoids ambiguity.
  • Use the formula bar to manually edit the function if you need to rename the output column. For example: = DateTimeZone.ToLocal([EventTime], "EventTime_Local").
  • Test the function on a small sample of data first. Use the "Sample" button in Power Query to preview results before applying to the full dataset.

Troubleshooting

  • If you see "Expression.Error: We cannot apply operator ToLocal to types Text and DateTimeZone", your column is still text. Convert it to DateTimeZone first using "Change Type" or the formula DateTimeZone.FromText([ColumnName]).
  • If the result shows the same time as the original, check your system’s time zone settings. Go to Windows Settings > Time & Language > Date & Time and ensure "Set time zone automatically" is on or the correct zone is selected.
  • If the function returns null, the source value may be invalid. Filter out nulls or use try ... otherwise to handle malformed entries: try DateTimeZone.ToLocal([Column]) otherwise null.
  • If the query fails after closing and reopening, ensure your system clock and time zone are synchronized. Power Query relies on the underlying OS time zone, which can drift if not properly updated.
  • If you're using Power BI Service (cloud), note that the conversion uses the time zone of the gateway or server, not your local machine. For consistent results in cloud reports, convert to UTC in Power Query and display local time in the visualization layer using DAX.

Frequently Asked Questions

What format must the input column be for DateTimeZone.ToLocal to work?

The input must be of type DateTimeZone. Valid formats include ISO 8601 strings like "2023-10-05T14:30:00+00:00" or native DateTimeZone values from APIs. Text strings without offsets (e.g., "2023-10-05 14:30") must be converted first.

Does DateTimeZone.ToLocal adjust for daylight saving time?

Yes. The function automatically applies the current daylight saving rules of your system’s time zone, including transitions into and out of DST.

Can I convert to a specific time zone instead of the local one?

No. DateTimeZone.ToLocal only converts to the machine’s local time zone. To convert to a specific time zone (e.g., "Europe/London"), use DateTimeZone.SwitchZone or DateTimeZone.FromText with a fixed offset.

Why does my result differ from the source time by exactly 5 hours?

This typically means your system is set to Eastern Daylight Time (UTC-4) or Central Daylight Time (UTC-5), and the source was in UTC. The difference reflects the offset between UTC and your local time zone during daylight saving.

Can I use this function in a DirectQuery mode in Power BI?

No. DateTimeZone.ToLocal is not supported in DirectQuery mode because it depends on the local machine’s time zone, which cannot be reliably determined on the server. Use it only in Import mode or convert times in DAX after loading.

Will the converted time change if I move my file to another computer?

Yes. The result reflects the local time zone of the machine opening the file. A file opened in New York will show different local times than the same file opened in Los Angeles. Always retain the original UTC or datetimezone column for consistency across locations.