CONVERT

The CONVERT function converts an expression from one type to another.

Syntax

CONVERT(
    expression,
    datatype
)

Parameters
  • expression: Any valid expression in DAX.
  • datatype: Type to apply to the previous expression.
Returned value

The CONVERT function returns the indicated expression with the new type.

Additional Information

The types available are:

  • INTEGER: Integer number.
  • DOUBLE: Real number.
  • STRING: Text string.
  • BOOLEAN: Boolean (True/False).
  • CURRENCY: Real number with four decimal places.
  • DATETIME: Date and time.

The function returns an error message when it cannot convert the expression to the indicated type.

Examples

We can convert a date to its equivalent as a whole number with the following expression:

Date to Int = CONVERT(DATE(2019, 10, 28), INTEGER)

If we take the result to a "card" type display, we obtain the following:

Función CONVERT

We can convert the same date into a text string with the following expression:

Date to Str = CONVERT(DATE(2019, 10, 28), STRING)

The result is as follows:

Función CONVERT

If we convert a real number to an integer, it is rounded if necessary:

Float to Int = CONVERT(4.5, INTEGER)

Función CONVERT

When converting texts to numbers, if the text can be converted correctly, the function returns the expression with the specified type:

Text to Int = CONVERT("7", INTEGER)

Función CONVERT

If it is not possible -because the string contains characters not compatible with the number format-, the function returns an error message:

Text to Int = CONVERT("7a", INTEGER)

Función CONVERT

We can convert an entire column from our data model:

Date to Int = CONVERT('Calendar'[Date], INTEGER)

Función CONVERT
Category
Other functions
Submitted by admin on Sun, 09/15/2019 - 11:32