Daily DAX : Day 339 HOUR
Power BI DAX HOUR Function
The HOUR function in Power BI DAX (Data Analysis Expressions) extracts the hour component from a given time or datetime value and returns it as an integer between 0 and 23.
Syntax
HOUR(datetime)
- datetime: A datetime value or a column containing datetime values (e.g., "2025-09-17 14:30:00").
Return Value
An integer from 0 to 23, representing the hour of the day in 24-hour format.
Use Case
The HOUR function is useful for analyzing time-based data, such as grouping or filtering data by specific hours of the day. Common scenarios include:
- Analyzing sales or user activity by hour (e.g., peak hours for transactions).
- Creating time-based reports or dashboards (e.g., visualizing hourly trends).
- Filtering data for specific time periods (e.g., business hours vs. after-hours).
Example
Suppose you have a table named Sales with a column TransactionTime containing datetime values. You want to create a calculated column to extract the hour of each transaction.
HourOfTransaction = HOUR(Sales[TransactionTime])
Sample Data:
TransactionTime | HourOfTransaction |
---|---|
2025-09-17 09:15:00 | 9 |
2025-09-17 14:45:00 | 14 |
2025-09-17 23:10:00 | 23 |
Use Case: You can use this calculated column to create a bar chart showing sales volume by hour to identify peak business hours.
Notes
- If the input is not a valid datetime, the function may return an error.
- The HOUR function works with 24-hour format (e.g., 1:00 PM returns 13).
- Can be used in calculated columns or measures for dynamic analysis.
Comments
Post a Comment