Dax Function: CONVERT

Category: Mathematical and Trigonometric Functions

The CONVERT function in Power BI is a versatile DAX (Data Analysis Expressions) function used to convert numbers from one unit of measurement to another. It is particularly useful for standardizing values in datasets containing measurements in different units, enabling better analysis and reporting.

Purpose

The CONVERT function is designed to simplify unit conversions, such as from meters to kilometers, grams to pounds, or Celsius to Fahrenheit. By automating unit transformations, it ensures consistency and eliminates manual calculation errors.

Type of Calculations

The CONVERT function performs unit-based calculations. It takes an input value and translates it into a corresponding value in a specified target unit using predefined conversion factors.

Practical Use Cases

  1. Unit Standardization: Converting mixed unit measurements into a common unit for analysis.
  2. Reporting: Displaying values in user-friendly or region-specific units (e.g., kilometers vs. miles).
  3. Forecasting: Ensuring all input data adheres to the same unit scale for predictive models.
  4. Cross-Border Analysis: Converting currency, temperature, or distance units for international comparisons.

CONVERT(<number>, <from_unit>, <to_unit>)</to_unit></from_unit></number>

ParameterTypeDescription
<number>ScalarThe numeric value to be converted.
<from_unit>StringThe unit of the input value (e.g., “m”, “km”, “lb”).
<to_unit>StringThe target unit for the conversion (e.g., “km”, “mi”, “kg”).


How Does CONVERT Dax Function Works?

  • The CONVERT function utilizes a predefined table of units and their respective conversion factors. It checks the compatibility of the input and output units, applies the relevant conversion formula, and returns the result.


    Supported Units

    The CONVERT function supports a wide range of units for categories such as length, mass, time, energy, temperature, and more. Examples include:

    • Length: “m” (meters), “km” (kilometers), “mi” (miles).
    • Mass: “g” (grams), “kg” (kilograms), “lb” (pounds).
    • Temperature: “C” (Celsius), “F” (Fahrenheit), “K” (Kelvin).


What Does It Return?

The function returns a scalar value representing the converted number in the specified target unit. If the provided units are invalid or incompatible, it returns an error.

When Should We Use It?

  • To harmonize datasets with mixed units.
  • To present data in units preferred by stakeholders or specific regions.
  • To perform accurate unit transformations in scientific or engineering contexts.

Examples

Basic Usage

Convert 100 meters to kilometers:


CONVERT(100, "m", "km")

Output: 0.1

Column Usage

If a column [Distance] contains distances in meters, and you want to convert them to kilometers:


= CONVERT([Distance], "m", "km")

Advanced Usage

Combining with other DAX functions to calculate converted totals:


= SUMX(Table, CONVERT([Value], "g", "kg"))

This sums the values in grams and converts the total to kilograms.

Tips and Tricks

      1. Unit Validation: Use Power BI’s documentation to ensure valid and compatible unit codes.
      2. Scaling: For large datasets, consider converting units at the data source to optimize performance.
      3. Error Handling: Wrap the CONVERT function in an IFERROR statement to handle invalid inputs gracefully.

      Potential Pitfalls

      • Incompatible Units: Ensure the from_unit and to_unit belong to the same measurement category.
      • Case Sensitivity: Unit strings are case-sensitive (e.g., “m” for meters, not “M”).
      • Unsupported Units: Check the official documentation for supported units, as custom units are not allowed.

Performance Impact of CONVERT DAX Function:

  • The CONVERT function is computationally efficient for small datasets but can slow down for large datasets due to repeated lookups of conversion factors. Optimize by pre-processing data when possible.

Related Functions You Might Need

  • ROUND: To round converted results to a specific number of decimal places.
  • FORMAT: To display converted values in user-friendly formats.
  • DIVIDE: To perform additional calculations on converted values.

Want to Learn More?
For more information, check out the official Microsoft documentation for CONVERT. You can also experiment with this function in your Power BI reports to explore its capabilities.

If you’re looking to unlock the full potential of Power BI and take your data insights to the next level, our expert Power BI consulting services are here to help. Whether you need assistance with implementing advanced DAX functions like the ones discussed here, creating interactive dashboards, or optimizing your data models for better performance, our team of seasoned Power BI consultants is ready to provide tailored solutions for your business. Visit our Power BI Consulting page to learn more about how we can empower your organization with data-driven decisions.

1. What is the CONVERT function used for in Power BI?

The CONVERT function is used to transform numerical values from one unit of measurement to another, such as meters to kilometers or Celsius to Fahrenheit.

2. Can the CONVERT function handle temperature conversions?

Yes, the CONVERT function supports temperature conversions, such as Celsius (“C”) to Fahrenheit (“F”) or Kelvin (“K”).

3. Are unit codes case-sensitive in the CONVERT function?

Yes, unit codes are case-sensitive. Ensure you use the correct capitalization (e.g., “m” for meters, not “M”).

4. Can I use the CONVERT function for custom units?

No, the CONVERT function only supports predefined units. Refer to Power BI documentation for the full list of supported units.

5. What happens if I use incompatible units in the CONVERT function?

The function will return an error if the from_unit and to_unit are incompatible or invalid.