Power Query Time.StartOfHour: How to Use It
In this article
Time.StartOfHour returns a time value truncated to the start of the hour (minutes and seconds set to zero). It is a built-in Power Query function that works on a time, datetime, or datetimezone value and is most often used to group timestamps into hourly buckets for reporting. You do not need to install anything extra, but you do need a query with a column that contains time or datetime values.
What You'll Need
- Power Query available in Excel, Power BI Desktop, or another Microsoft tool that hosts Power Query.
- A query with a column that holds time, datetime, or datetimezone values. If your column is text, convert it to a time or datetime type first.
- Basic familiarity with the Power Query Editor and the formula bar.
Step-by-Step
- Open the Power Query Editor. In Excel, go to Data > Get & Transform Data > Launch Power Query Editor. In Power BI Desktop, go to Home > Transform data. Menu labels can differ slightly by version and platform.
- Load or select the query that contains your time or datetime column. If the column is text, right-click the column header, choose Change Type, and pick Time, Date/Time, or Date/Time/Zone as appropriate.
- Add a custom column. On the Home tab, click Custom Column. In the dialog, give the new column a name such as HourStart.
- Enter the formula in the Custom Column box. For a time column named Time, use
Time.StartOfHour([Time]). For a datetime column named Timestamp, useTime.StartOfHour([Timestamp]). The function accepts time, datetime, and datetimezone values and returns a time value. - Click OK. A new column appears with each row truncated to the start of its hour. For example, 14:37:52 becomes 14:00:00 and 09:05 becomes 09:00:00.
- Check the new column's data type. Power Query usually assigns Time automatically. If it shows as Any, click the type icon in the column header and choose Time.
- Use the column for grouping or filtering. To group by hour, select the new column and use Home > Group By, or use it in a visual in Power BI or a PivotTable in Excel.
- Rename the query or column if needed, then close and load. In Excel, choose Home > Close & Load. In Power BI Desktop, choose Home > Close & Apply.
Common Mistakes
- Passing a text column directly. Time.StartOfHour expects a time, datetime, or datetimezone value; a text column causes an error. Convert the column type first.
- Expecting a datetime result. The function returns only the time portion, so the date is lost. If you need the date preserved, use DateTime.From with the original date and the truncated time, or use DateTime.StartOfHour if your version provides it.
- Using the wrong column name. The formula must match the exact column name, including spaces. If the name contains spaces, wrap it in square brackets as usual, for example
Time.StartOfHour([Order Time]). - Forgetting that nulls propagate. If the source value is null, the result is null. Handle nulls with a conditional column or by filtering before applying the function.
- Assuming time zones are adjusted. The function truncates the value you give it; it does not convert between time zones. For datetimezone values, the offset is not changed by the function.
Tips
- Use Time.StartOfHour to create a clean hour bucket for charts, then add a second column for the date if you need a full datetime key.
- If your source has separate date and time columns, combine them with DateTime.From before truncating, or keep them separate and group by both.
- For rounding to the nearest hour instead of truncating, add 30 minutes before calling the function, then truncate. For example,
Time.StartOfHour(Time.From([Time]) + #duration(0,0,30,0)). - Name the new column clearly, such as HourStart, so report consumers know it is a truncated value and not the original timestamp.
- Apply the step after any filtering that removes nulls or invalid values to avoid errors during refresh.
Troubleshooting
If the custom column shows an error, click the error link to see the message. A common message is that the value is not a time. In that case, change the source column type to Time or Date/Time and refresh the preview. If the column name in the formula does not match, Power Query reports that the field was not found; check spelling and spaces. If the result is blank, the source value is probably null; filter nulls or add a fallback value. If the function is not recognized, confirm you are using a current version of Excel or Power BI Desktop, since older versions may not include it. If the query is slow, apply the step after reducing rows with filters rather than before.
Frequently Asked Questions
What does Time.StartOfHour return?
It returns a time value with minutes and seconds set to zero, based on the hour of the input value.
Can I use it on a datetime column?
Yes. It accepts time, datetime, and datetimezone values and returns only the time portion.
Does it keep the date?
No. The result is a time value only. To keep the date, combine the original date with the truncated time using DateTime.From.
What happens with null values?
The result is null. Filter or replace nulls before applying the function if you need a value for every row.
Is there a DateTime.StartOfHour function?
Availability varies by version. If it is not available in your editor, use Time.StartOfHour and combine it with the date as described above.
Can I round to the nearest hour instead of truncating?
Yes. Add 30 minutes to the time before calling Time.StartOfHour, then truncate.