TIMEVALUE

How to Use the Power BI DAX function TIMEVALUE

What is the TIMEVALUE Function in Power BI?

The TIMEVALUE function is one of the many built-in DAX functions available in Power BI. Its primary purpose is to convert a text string that represents a time into a proper time value that can be used in calculations and visualizations. The syntax of the function is as follows:


TIMEVALUE(❰text❱)


Here, `❰text❱` is the text string that represents the time you want to convert. The string must be in a format that can be recognized as a time value, such as "12:30 PM" or "3:45 AM".

The function returns a decimal value that represents the time in the internal format used by Power BI. This value can be further manipulated and formatted as needed using other DAX functions or visualizations.

Using the TIMEVALUE Function in Power BI

To use the TIMEVALUE function in Power BI, you first need to have a text string that represents the time you want to convert. This string can come from a variety of sources, such as a database query, a CSV file, or user input.

Once you have the text string, you can use the TIMEVALUE function to convert it into a time value. Here is an example of how to use the function in a DAX formula:


MyTimeValue = TIMEVALUE(“3:45 PM”)


In this example, we are using the TIMEVALUE function to convert the text string "3:45 PM" into a time value, which is then assigned to the variable MyTimeValue. We can then use this variable in other calculations or visualizations as needed.

Tips for Using the TIMEVALUE Function

Here are some tips to keep in mind when using the TIMEVALUE function in Power BI:

- The text string you provide to the function must be in a format that can be recognized as a time value. If the string is not in the correct format, the function will return an error.

- The TIMEVALUE function assumes that the time is in the 24-hour clock format by default. If you want to use the 12-hour clock format, you need to include the "AM" or "PM" designation in the text string.

- If you have a date and time value in a single text string, you can use the DATEVALUE and TIMEVALUE functions together to extract the individual values. For example, if you have the string "2022-01-15 3:45 PM", you can use the following formula to extract the time value:


MyTimeValue = TIMEVALUE(RIGHT(“2022-01-15 3:45 PM”, 8))


In this formula, the RIGHT function is used to extract the last 8 characters of the string, which represent the time value. The TIMEVALUE function is then used to convert this value into a proper time value.

The TIMEVALUE function is a powerful tool for working with time values in Power BI. By converting textual representations of time into proper time values, you can perform a variety of calculations and visualizations that would otherwise be difficult or impossible. If you are working with time-based data in Power BI, be sure to give the TIMEVALUE function a try.

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)