What is the HOUR function in Power BI?
The HOUR function in Power BI is a DAX function that extracts the hour value from a datetime or time column. It returns an integer value between 0 and 23, representing the hour of the day.
Syntax of the HOUR function
The syntax of the HOUR function is as follows:
The ❰datetime❱ argument is a reference to a datetime or time column from which you want to extract the hour value.
Example of using the HOUR function
Suppose you have a datetime column called "OrderDate" in your data model, and you want to extract the hour value from it. You can use the HOUR function as follows:
This will return an integer value representing the hour of the day for each row in the "OrderDate" column.
Using the HOUR function with other DAX functions
The HOUR function can be used in combination with other DAX functions to perform more complex calculations. For example, you can use the HOUR function with the SUMX function to calculate the total sales for each hour of the day.
= SUMX(Orders, IF(HOUR(Orders[OrderDate]) = 10, Orders[Sales], 0))
This formula will calculate the total sales for the 10th hour of the day.
Using the HOUR function with conditional statements
You can also use the HOUR function with conditional statements to filter your data based on the hour value. For example, you can use the HOUR function with the FILTER function to filter your data to show only the orders that were placed between 9 AM and 5 PM.
= FILTER(Orders, AND(HOUR(Orders[OrderDate]) ❱= 9, HOUR(Orders[OrderDate]) ❰= 17))
This formula will filter the "Orders" table to show only the orders that were placed between 9 AM and 5 PM.
The HOUR function in Power BI is a useful tool for extracting the hour value from a datetime or time column. It can be used in combination with other DAX functions and conditional statements to perform more complex calculations and filter your data based on the hour value. By using the HOUR function, you can gain valuable insights into your data and make better-informed business decisions.
Power BI DAX Training Courses by G Com Solutions (0800 998 9248)
Power BI DAX Intensive Training Course£1,050.00 – £26,550.00
Power BI DAX Introduction£395.00 – £9,750.00
Power BI DAX Intermediate£395.00 – £9,750.00
Power BI DAX Advanced£395.00 – £9,750.00