Code Generator | DAX

Dynamic DAX Measure Selector for Power BI

This DAX function dynamically outputs specific measures based on user selections in Power BI filters, enhancing interactivity on dashboards by seamlessly switching between different metrics like Total Sales, Profit, or Quantity Sold.


Empty image or helper icon

Prompt

when I select a value from filter it gives a particular measure as output

Answer

DAX Function for Dynamic Measure Output

Overview

The following DAX function allows you to output a specific measure based on the selection from a filter. This solution is useful for dashboards in Power BI where users can interactively filter and see the results change dynamically.

Function Definition

DynamicMeasureOutput = 
VAR SelectedValue = SELECTEDVALUE('YourTable'[YourColumn], "Default")
RETURN 
    SWITCH(
        SelectedValue,
        "Value1", [Measure1],
        "Value2", [Measure2],
        "Value3", [Measure3],
        BLANK()  // Output is blank if no valid selection is made.
    )

Explanation:

  • SELECTEDVALUE: This function checks for a selected value in the specified column. If no selection is made, it defaults to "Default".
  • SWITCH: This function evaluates the selected value and returns corresponding measures. If the selected value does not match any of the specified cases, it returns BLANK().

Input Validation

In essence, the input handling is managed by SELECTEDVALUE, which automatically handles scenarios where no selection is made.

Inline Comments

  • VAR SelectedValue: Stores the currently selected value from the slicer/filter.
  • RETURN: Outputs the result based on the conditions defined in SWITCH.

Example Usage

Suppose you have a slicer on the column [YourColumn] in YourTable, which includes the values "Value1", "Value2", and "Value3". You also have three measures defined:

  • Measure1: Total Sales
  • Measure2: Total Profit
  • Measure3: Total Quantity Sold

In your Power BI report, when a user selects "Value1" from the filter, the DynamicMeasureOutput will return the result of [Measure1]. If "Value2" is selected, it will return [Measure2], and so forth.

Conclusion

This DAX function is efficiently designed to provide dynamic measure outputs based on user selection, enhancing interactivity in your reporting solutions. For further mastery of DAX and Power BI, consider exploring courses on the Enterprise DNA platform.

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

Description

This DAX function dynamically outputs specific measures based on user selections in Power BI filters, enhancing interactivity on dashboards by seamlessly switching between different metrics like Total Sales, Profit, or Quantity Sold.