TIME

How to Use the Power BI DAX function TIME

What is the TIME Function?

The TIME function is a DAX function that returns a time value based on the specified hour, minute, and second values. The syntax for the TIME function is as follows:


TIME(hour, minute, second)


Where:

- `hour`: The hour value (0-23).

- `minute`: The minute value (0-59).

- `second`: The second value (0-59).

The TIME function returns a time value in the format `hh:mm:ss`, where `hh` represents the hour, `mm` represents the minute, and `ss` represents the second.

Using the TIME Function in Power BI

To use the TIME function in Power BI, you can follow these steps:

1. Open a new or existing Power BI report.

2. Click on the "Modeling" tab in the ribbon.

3. Click on "New Column" in the "Calculations" group.

4. In the formula bar, enter the following formula:


Time = TIME(hour, minute, second)


5. Replace `hour`, `minute`, and `second` with the desired values.

6. Press Enter to create the new column.

The new column will be added to the data model and can be used in visualizations and calculations.

Examples of Using the TIME Function

Let's take a look at some examples of using the TIME function in Power BI.

Example 1: Creating a Time Table

One common use case for the TIME function is to create a time table that can be used for time-based calculations and visualizations. To create a time table, follow these steps:

1. Open a new or existing Power BI report.

2. Click on the "Modeling" tab in the ribbon.

3. Click on "New Table" in the "Calculations" group.

4. In the formula bar, enter the following formula:


TimeTable = ADDCOLUMNS(

CALENDAR(DATE(2021, 1, 1), DATE(2021, 12, 31)),

“Time”, TIME(HOUR([Date]), MINUTE([Date]), SECOND([Date]))

)


5. Press Enter to create the new table.

This formula creates a time table for the year 2021 with a granularity of one second. The time value is calculated based on the hour, minute, and second values extracted from the date column.

Example 2: Calculating Time Differences

Another use case for the TIME function is to calculate the difference between two time values. To calculate the time difference, follow these steps:

1. Open a new or existing Power BI report.

2. Click on the "Modeling" tab in the ribbon.

3. Click on "New Column" in the "Calculations" group.

4. In the formula bar, enter the following formula:


TimeDiff = [Time2] – [Time1]


5. Replace `Time1` and `Time2` with the names of the columns that contain the time values.

6. Press Enter to create the new column.

This formula calculates the time difference between two time values and returns the result in the format `hh:mm:ss`.

The TIME function is a powerful DAX function that can be used to create custom time-based calculations and visualizations in Power BI. By following the steps outlined in this article, you can start using the TIME function in your own Power BI reports and dashboards.

Power BI DAX Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)