Dax Function: HOUR
Category: Date and Time Functions
The HOUR function in Power BI is a DAX (Data Analysis Expressions) function used to extract the hour component from a datetime value.
Purpose
To retrieve the hour as an integer (0–23) from a given datetime or time value.
Type of Calculations
Time manipulation and analysis.
Practical Use Cases
- Breaking down datetime data into hourly segments for analysis.
- Identifying specific time periods (e.g., business hours vs. non-business hours).
- Grouping data by hour for reporting or visualization.
HOUR()
Parameter | Type | Description |
---|---|---|
datetime | Datetime | A valid datetime or time value from which the hour component will be extracted. |
How Does HOUR Dax Function Works
- The function interprets the
datetime
input. - It isolates the hour portion of the given time.
- The result is a number from
0
(midnight) to23
(11:00 PM), based on a 24-hour clock format.
Example: For datetime
= 2025-02-10 15:45:00
, the result is 15
.
What Does It Return?
- Type: Integer.
- Meaning: Returns the hour (0–23) of the given datetime value.
When Should We Use It?
- Extracting time-based insights from datetime columns.
- Identifying peak hours in sales or operations data.
- Creating custom filters or conditions based on specific hours.
Examples
Basic Usage
Extract the hour from the current date and time:
HOUR(NOW())
Output: If the current time is 2025-02-10 14:30:00
, the result is 14
.
Column Usage:
Add a calculated column to extract the hour from a datetime column:
OrderHour = HOUR(Table[OrderDate])
For OrderDate
= 2023-07-21 09:15:00
, the result is 9
.
Advanced Usage
Group sales data by hour and calculate total sales:
TotalSalesByHour = SUMX(
FILTER(Table, HOUR(Table[OrderDate]) = 14),
Table[SalesAmount]
)
This calculates total sales for orders placed at 2:00 PM.
Tips and Tricks
- Use HOUR alongside MINUTE and SECOND for more granular time-based analysis.
- Pair with DATE or NOW to dynamically filter or segment data by hours.
- Be cautious when working with time zones—ensure that datetime values are in the correct time zone for accurate analysis.
Potential Pitfalls
- If the
datetime
parameter contains null or invalid values, the function will return an error. Use functions likeISBLANK
orIFERROR
to handle such cases. - The function does not support time formats outside standard datetime values. Ensure data is properly formatted.
Performance Impact of HOUR DAX Function:
- Efficient for large datasets when used in calculated columns or measures.
- Precompute hour values during data preparation in Power Query if performance becomes an issue.
Related Functions You Might Need
- MINUTE: Extracts the minute component from a datetime value.
- SECOND: Extracts the second component from a datetime value.
- TIME: Combines hour, minute, and second values into a time.
- NOW: Returns the current datetime.
Want to Learn More?
For more information, check out the official Microsoft documentation for HOUR. You can also experiment with this function in your Power BI reports to explore its capabilities.
Unlock the full capabilities of Power BI and elevate your data insights with our specialized consulting services. Whether you need guidance on advanced DAX functions like those highlighted here, support in designing interactive dashboards, or expertise in optimizing data models for enhanced performance, our experienced Power BI consultants are equipped to deliver customized solutions for your business. Explore our Power BI Consulting Services page to discover how we can help your organization make smarter, data-driven decisions.
The HOUR function extracts the hour component (0–23) from a given datetime or time value.
Yes, the function can handle time-only fields and will extract the hour portion.
The function will return an error. Handle null values with IFERROR
or ISBLANK
.
The function always returns the hour in a 24-hour clock format (e.g., 2:00 PM = 14).
Yes, you can extract the hour as a calculated column or measure and use it for grouping or segmentation.
Established in 2020, Lets Viz Technologies provides a full range of high-quality data analysis and data visualization services. We are also an authorized Zoho Partner.
Sitelinks