Smart Systems for Home

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

DateTimeZone.ZoneMinutes Guide for Power Query

· 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.ZoneMinutes function in Power Query (M language) extracts the minute component of the UTC offset from a datetimezone value. This is essential when dealing with time zones that do not offset by full hours, such as India Standard Time (UTC+5:30) or Nepal Standard Time (UTC+5:45), allowing you to isolate the specific minute deviation for calculations or reporting.

What You'll Need

  • Microsoft Excel (with Power Query) or Power BI Desktop.
  • A dataset containing a column with the datetimezone data type.
  • Access to the Power Query Editor (Transform Data).

Step-by-Step

  1. Load Your Data: Open Power BI Desktop or Excel. Go to the Data tab (Excel) or Home tab (Power BI) and select Get Data to import your source. Once the data is loaded into the Power Query Editor, locate the column containing your date and time information.
  2. Verify Data Type: Look at the icon to the left of the column header. It must show a small calendar and clock icon with a globe (the datetimezone type). If it only shows a calendar and clock (datetime), the ZoneMinutes function will return an error. To change this, right-click the column header, select Change Type, and choose DateTimeZone.
  3. Create a Custom Column: Navigate to the Add Column tab on the top ribbon. Click on Custom Column. This opens the Custom Column dialog box where you can write your M formula.
  4. Enter the Formula: In the Custom column formula box, type the following: = DateTimeZone.ZoneMinutes([YourColumnName]). Replace [YourColumnName] with the actual name of your column by double-clicking it from the list of available columns on the right side of the dialog.
  5. Confirm and Apply: Click OK. Power Query will create a new column containing a whole number representing the minutes of the offset. For example, if the time zone is UTC+05:30, the resulting value in this column will be 30.
  6. Set the New Column Type: The new column will likely be set to the 'Any' type by default. Click the data type icon in the header of the new column and select Whole Number to ensure it is treated as a numeric value for any subsequent math.

Common Mistakes

The most frequent error is attempting to use DateTimeZone.ZoneMinutes on a standard datetime or datetimezone.local value that has been cast to a simple date. If the data type is not explicitly datetimezone, Power Query cannot find the offset metadata, resulting in an Expression.Error stating that the value cannot be converted to a DateTimeZone.

Another common mistake is confusing DateTimeZone.ZoneMinutes with Time.Minute. Time.Minute extracts the minute of the hour from the actual time of day (e.g., if it is 10:15 AM, it returns 15). DateTimeZone.ZoneMinutes extracts the minute portion of the UTC offset (e.g., if the offset is +05:30, it returns 30). Using the wrong function will lead to logically incorrect data in your reports.

Users also often forget that the function only returns the minute part of the offset, not the total offset in minutes. If a time zone is UTC+05:30, ZoneMinutes returns 30, not 330 (which would be 5 hours * 60 + 30). To get the total offset, you must combine ZoneHours and ZoneMinutes.

Tips

To calculate the total UTC offset in minutes, create a custom column using a formula that combines hours and minutes. Use: (DateTimeZone.ZoneHours([YourColumnName]) * 60) + DateTimeZone.ZoneMinutes([YourColumnName]). This provides a single numeric value that is much easier to use for time-shifting calculations across different global regions.

When working with data from various sources, use the DateTimeZone.UtcNow() function to create a baseline for comparison. By subtracting the local datetimezone value from the UTC value, you can verify if the ZoneMinutes extracted matches the expected regional offset.

If you are building a reusable template, consider creating a custom function in the M language. This allows you to pass any column into a named function rather than writing the DateTimeZone.ZoneMinutes syntax repeatedly across multiple queries in the same project.

Troubleshooting

If you encounter an error saying "We cannot convert the value to type DateTimeZone," check your source data. Often, data imported from CSVs is treated as Text. You must first convert the text to a datetimezone type using the Change Type menu. If the text format is non-standard, you may need to use DateTimeZone.FromText before applying the ZoneMinutes function.

If the function returns 0 when you expect a value, verify the time zone of the source data. Many systems export data in UTC (Coordinated Universal Time). Since UTC has an offset of +00:00, the ZoneMinutes result will be 0. This is not a function error, but a reflection of the data's properties. Check if the source system is actually providing the local offset or if it is normalizing everything to UTC before export.

If the result is a negative number, do not be alarmed. Time zones west of the Prime Meridian (such as those in the Americas) have negative offsets. For example, a time zone of UTC-04:00 will return 0 for minutes, but if it were a fractional zone like UTC-03:30, it would return -30. Ensure your downstream calculations account for negative integers.

Frequently Asked Questions

Does this function work with standard DateTime columns?

No. It requires the datetimezone data type. If you use it on a standard datetime column, Power Query will throw a type mismatch error because standard date-times do not store offset information.

What is the difference between ZoneMinutes and Time.Minute?

Time.Minute returns the minute of the current hour (0-59). DateTimeZone.ZoneMinutes returns the minute portion of the UTC offset (usually 0, 15, 30, or 45) used to define a region's time zone.

Can I use this to convert local time to UTC?

While ZoneMinutes helps you identify the offset, it is more efficient to use DateTimeZone.ToUtc to perform the actual conversion. Use ZoneMinutes specifically when you need to report on or analyze the offset itself.

Why is my result always 0?

This happens if your data is already in UTC or if the time zone offset is a whole number of hours (e.g., UTC+1, UTC-5). In these cases, there are no additional minutes in the offset, so the function correctly returns 0.

Does this function handle Daylight Savings Time (DST) automatically?

The function extracts the offset present in the specific datetimezone value provided. If the value was recorded during DST and the offset changed, the function will return the offset as it existed at that specific moment in time.

Can I use this in a Power BI DAX measure?

No, DateTimeZone.ZoneMinutes is an M function used in the Power Query Editor. To achieve similar results in DAX, you would need to perform the extraction in Power Query first or use complex time-shifting logic within your DAX measures.