Extracting Hour from a Datetime in Power BI

Extracting Hour from a Datetime in Power BI, When working with datetime data in Power BI, you might often need to extract specific components, like the hour, from the datetime values.

Power BI makes this task easy using DAX functions. In this article, we’ll demonstrate how to extract the hour from a datetime column using the HOUR function in DAX.

Extracting Hour from a Datetime in Power BI

To extract the hour from a datetime column in Power BI, use the following DAX formula:

hour = HOUR('my_data'[Datetime])

This example creates a new column named hour that extracts the hour from the Datetime column in the my_data table.

Practical Example: Extract Hour from Datetime in Power BI

Let’s see how this works in practice. Suppose we have a table named my_data in Power BI containing information about total sales made by a company at specific datetimes.

We want to extract the hour from each datetime in the Datetime column.

  1. Click the Table Tools Tab:
  • First, navigate to the Table Tools tab in Power BI.
  1. Create a New Column:
  • Click the New Column icon.
  1. Enter the DAX Formula:
  • In the formula bar, type the following formula:
   hour = HOUR('my_data'[Datetime])

This will create a new column named hour that contains only the hour extracted from each datetime in the Datetime column.

Example Outputs

Here are a few examples of how the formula extracts the hour from various datetime values:

  • The formula extracts 10 from 1/1/2024 10:15:00 AM.
  • The formula extracts 19 from 1/5/2024 7:15:23 PM.
  • The formula extracts 1 from 2/15/2024 1:15:09 AM.

And so on.

Conclusion

Extracting the hour from a datetime in Power BI is a straightforward process with the HOUR function in DAX.

This functionality can be particularly useful for time-based analyses and reporting.

Power BI Archives ยป FINNSTATS

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

4 × one =