Smart Systems for Home

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

Power Query Time.Minute Function: How to Extract Minutes

· 6 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 Time.Minute function in Power Query is used to extract the minute component from a time or datetime value, returning an integer between 0 and 59. To use it, you simply wrap your time column or value in the function, such as Time.Minute([YourTimeColumn]), within a Custom Column formula. This is essential for data analysts who need to group data by specific time intervals, calculate duration offsets, or isolate the minute for reporting purposes.

What You'll Need

  • Microsoft Excel or Power BI Desktop.
  • A dataset containing a column formatted as Time, Date/Time, or DateTimeZone.
  • Access to the Power Query Editor (accessed via Data > Get Data or Transform Data).

Step-by-Step

  1. Open the Power Query Editor: In Excel, go to the Data tab and select Get Data or click on an existing query to launch the editor. In Power BI, click Transform Data on the Home ribbon.
  2. Verify Data Types: Look at the icon to the left of your column header. It must be a clock icon (Time) or a calendar-and-clock icon (Date/Time). If it says ABC or 123, right-click the column header, select Change Type, and choose Time or Date/Time. Note that labels may differ slightly depending on your software version or region.
  3. Create a Custom Column: Navigate to the Add Column tab on the top ribbon and select Custom Column. This opens a dialog box where you can define your new calculation.
  4. Enter the Formula: In the Custom column formula box, type = Time.Minute([ColumnName]). Replace [ColumnName] by double-clicking the name of your time column from the list of available columns on the right side of the dialog.
  5. Validate the Formula: Check the bottom of the dialog box for the message "No syntax errors have been detected." If you see an error, ensure you have used a capital 'T' and 'M' as Power Query (M language) is case-sensitive.
  6. Confirm and Apply: Click OK. A new column will appear at the end of your table containing only the minute values (0-59).
  7. Set the New Column Type: By default, the new column may be set to "Any." Click the data type icon in the column header and select Whole Number to ensure it can be used in mathematical calculations.
  8. Close and Apply: Go to the Home tab and select Close & Apply to load the extracted minute data back into your Excel worksheet or Power BI model.

Common Mistakes

One of the most frequent errors is ignoring case sensitivity. In the M language, time.minute or Time.minute will result in a "Token Literal expected" or "The name 'time.minute' wasn't recognized" error. The function must be written exactly as Time.Minute.

Another common mistake is attempting to use the function on a column that is formatted as Text. If your time data was imported from a CSV and is currently a Text type, the function will return an error for every row because it cannot perform a time operation on a string of characters. You must explicitly convert the column to a Time type before applying the function.

Users also often confuse Time.Minute with duration calculations. Time.Minute only looks at the "clock time" (the minute hand position). If you are trying to find the total number of minutes in a duration (e.g., a task that took 125 minutes), this function will not work, as it only returns values up to 59. For total elapsed minutes, you would need to use Duration.TotalMinutes.

Tips

To avoid writing manual formulas, you can use the built-in GUI. Select your time column, go to the Add Column tab, click the Time dropdown menu, select Time, and then select Minute. Power Query will automatically generate the Time.Minute code for you in the background.

If you are creating a "Time Bucket" (e.g., grouping data into 15-minute intervals), you can combine Time.Minute with integer division. For example, Number.IntegerDivide(Time.Minute([Time]), 15) will categorize your data into buckets 0, 1, 2, and 3, which you can then multiply by 15 to get the start of the interval.

When working with very large datasets, it is more efficient to use the "Add Column from Examples" feature. You can type the minute you want to see for the first two rows, and Power Query will often suggest the Time.Minute function automatically, saving you from typing the syntax manually.

Troubleshooting

If you encounter an "Expression.Error: We cannot convert the value to type Time" message, the first step is to check for null values or invalid time entries (like "N/A" or empty strings) in your source column. Nulls are generally handled gracefully, but text strings in a time column will break the function. Use the Replace Errors or Replace Values feature to clean the data before applying the function.

If the function returns the wrong minute, check your regional settings. Some regions use different time formats (12-hour vs 24-hour). While Time.Minute is generally agnostic to the hour format, the initial conversion from Text to Time might fail or shift the time if the locale is not set correctly. You can fix this by right-clicking the column, selecting Change Type > Using Locale..., and choosing the origin country of the data.

If the column appears empty or shows errors after you have applied the steps, check the Applied Steps pane on the right. Ensure that the "Changed Type" step occurs before the "Added Custom" step. If you changed the type after trying to extract the minute, the function failed because the data was still text at the moment the calculation was attempted. Drag the steps to reorder them.

Frequently Asked Questions

Does Time.Minute work with Date/Time columns?

Yes. The function is designed to accept any value that can be cast as a time. If you provide a Date/Time value, it simply ignores the date portion and extracts the minute from the time portion.

What is the difference between Time.Minute and Duration.Minutes?

Time.Minute extracts the minute component of a specific time of day (e.g., 10:45 AM returns 45). Duration.Minutes returns the minute component of a time span (e.g., a duration of 1 hour and 10 minutes returns 10).

Can I use this function to round time to the nearest minute?

No, Time.Minute only extracts the current value. To round time, you would typically extract the minutes, use Number.Round on that value, and then reconstruct the time using #time().

Will this function work if my time is in a different time zone?

The function extracts the minute as it appears in the value. If you are using a DateTimeZone type, it will extract the minute from the local time represented in that value unless you first convert it to a different zone using DateTimeZone.ToLocal or DateTimeZone.SwitchZone.

Why is my result showing as a decimal instead of a whole number?

The function itself always returns an integer. If you see decimals, it is likely because the column data type was set to "Decimal Number" or "Fixed Decimal Number" in a subsequent step. Change the data type to "Whole Number" to fix this.