Smart Systems for Home

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

Power Query Time.ToRecord: Step-by-Step Guide

· 4 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

Time.ToRecord converts a time value into a record with three fields: Hour, Minute, and Second. For example, Time.ToRecord(#time(14, 30, 15)) returns [Hour = 14, Minute = 30, Second = 15]. This is useful when you need to extract individual time components for calculations, filtering, or building custom columns in Power Query. You need Power Query Editor open in Excel or Power BI, and a column containing time values or a time literal to work with.

What You'll Need

  • Power Query Editor open in Excel (Data > Get & Transform Data > Launch Power Query Editor) or Power BI Desktop (Home > Transform data). Menu labels may differ slightly by version or region.
  • A query with a column of type Time, or the ability to create a time value using #time(hour, minute, second).
  • Basic familiarity with adding custom columns and writing M formulas.

Step-by-Step

  1. Load your data into Power Query. In Excel, select your table and go to Data > From Table/Range. In Power BI, use Home > Transform data to open the editor. Ensure the column you want to convert is present.
  2. Set the column type to Time. Select the column, go to the Home tab, click the data type icon (e.g., ABC/123) and choose Time. If the column contains text like "14:30:15", Power Query may auto-detect it; if not, use Transform > Data Type > Using Locale and pick a locale that matches your time format.
  3. Add a custom column. Go to Add Column > Custom Column. In the dialog, give it a name (e.g., "TimeRecord") and enter the formula: Time.ToRecord([YourTimeColumn]). Replace [YourTimeColumn] with your actual column name.
  4. Check the result. The new column will show [Record] in each cell. Click the expand icon (two arrows) in the column header to see the fields Hour, Minute, and Second. Select the ones you want to keep and click OK.
  5. Use the fields. After expanding, you can rename columns, change types (e.g., to Whole Number), and use them in calculations. For example, create a custom column that multiplies Hour by 60 and adds Minute to get total minutes.
  6. Handle nulls. If your time column contains nulls, Time.ToRecord will return null. To avoid errors, wrap the formula in a null check: if [YourTimeColumn] = null then null else Time.ToRecord([YourTimeColumn]).
  7. Apply and close. Click Home > Close & Load (Excel) or Home > Close & Apply (Power BI) to load the transformed data.

Common Mistakes

  • Using a text column. Time.ToRecord expects a time value, not text. If you pass text, you'll get an error. Convert the column to Time type first.
  • Forgetting to expand the record. The custom column shows [Record] until you expand it. Many users think the function failed when they just need to click the expand icon.
  • Ignoring nulls. Null inputs produce null records, which can cause errors downstream. Always add a null check if your data might have blanks.
  • Assuming Time.ToRecord handles dates. It only works with time values. For dates, use Date.ToRecord; for datetime, use DateTime.ToRecord.
  • Misnaming fields. The record fields are always Hour, Minute, Second (capitalized). If you reference them in later steps, use exact names.

Tips

  • You can use Time.ToRecord directly in a custom column formula without creating a separate step.
  • To extract just one component, use Time.Hour, Time.Minute, or Time.Second instead of converting to a record—it's simpler and faster.
  • When expanding records, you can choose to expand all fields at once or select specific ones. Use the expand icon's options to avoid extra columns.
  • If you need to convert a duration (not a time of day), use Duration.ToRecord instead.
  • Combine Time.ToRecord with other functions like Time.From to parse text, then extract components.

Troubleshooting

If Time.ToRecord returns an error, check the column type first. A common error is "We cannot convert a value of type Text to type Time." Fix it by changing the column type to Time. If the column contains values like "2:30 PM", Power Query may not recognize them as time; use Transform > Replace Values to remove AM/PM and convert to 24-hour format, or use Time.From with a locale. If the function returns null, the input is null—add a null check. If the record fields don't appear after expanding, ensure you clicked the expand icon and not just the column header. If you see [Record] but no expand icon, the column may be typed as Any; change it to Record type. For performance, avoid using Time.ToRecord on very large tables if you only need one component; use Time.Hour, Time.Minute, or Time.Second instead.

Frequently Asked Questions

What does Time.ToRecord return?

It returns a record with three fields: Hour, Minute, and Second, each as a number.

Can I use Time.ToRecord on a column with datetime values?

No, it expects a time value. Use DateTime.ToRecord for datetime, or extract the time part first with DateTime.Time.

How do I expand the record fields?

Click the expand icon (two arrows) in the column header of the custom column, then select the fields you want.

Why do I get an error when using Time.ToRecord?

Most likely the column is not typed as Time. Change the data type to Time and try again.

Is Time.ToRecord available in all Power Query versions?

Yes, it is a standard M function available in Excel and Power BI.

Can I use Time.ToRecord with a literal time?

Yes, for example Time.ToRecord(#time(14,30,15)) returns [Hour=14, Minute=30, Second=15].