Time.StartOfHour

Time

Returns the first moment of the hour for the given time or datetime value.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Time.StartOfHour(dateTime as any) as any

Parameters

NameTypeRequiredDescription
dateTimeanyYesA time, datetime, or datetimezone value.

Return Value

anyA time, datetime, or datetimezone value representing XX:00:00.

Remarks

Time.StartOfHour returns the first instant of the clock hour containing the input value: XX:00:00. When passed a plain time, it returns a time with minutes and seconds set to zero. When passed a datetime or datetimezone, it returns the same type with only the time component adjusted — the date and any timezone offset are preserved unchanged. This is useful for bucketing events into hourly groups or building inclusive hourly range filters.

Pair Time.StartOfHour with Time.EndOfHour using the same input to construct a complete inclusive hourly boundary: [EventTime] >= Time.StartOfHour(ref) and [EventTime] <= Time.EndOfHour(ref). Use Time.StartOfHour as the grouping key for hourly aggregations — group by Time.StartOfHour([Timestamp]) to bucket all events into their clock hour.

For truncating a datetime to midnight (start of day) rather than the start of an hour, use Date.StartOfDay instead.

Examples

Example 1: Truncate log timestamps to the hour

Table.AddColumn(
    Table.SelectColumns(Table.FirstN(OrderLog, 4), {"LogID", "Timestamp"}),
    "HourStart", each Time.StartOfHour([Timestamp]), type datetime
)
Result
LogID
Timestamp
HourStart
1L0011/15/2024 9:30:00 AM1/15/2024 9:00:00 AM
2L0021/16/2024 2:15:00 PM1/16/2024 2:00:00 PM
3L0031/18/2024 11:00:00 AM1/18/2024 11:00:00 AM
4L0041/20/2024 8:45:00 AM1/20/2024 8:00:00 AM

Example 2: Start of hour for a specific time

#table(
    type table [Result = time],
    {{Time.StartOfHour(#time(14, 30, 45))}}
)
Result
Result
114:00:00

Example 3: Group log entries by clock hour

Table.Group(
    Table.AddColumn(OrderLog, "HourStart", each Time.StartOfHour([Timestamp]), type datetime),
    {"HourStart"},
    {{"EventCount", each Table.RowCount(_), Int64.Type}}
)
Result
HourStart
EventCount
11/15/2024 9:00:00 AM1
21/16/2024 2:00:00 PM1
31/18/2024 11:00:00 AM1
41/20/2024 8:00:00 AM1
52/1/2024 4:00:00 PM1
62/2/2024 10:00:00 AM1
72/10/2024 1:00:00 PM1
82/12/2024 9:00:00 AM1

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks