DAX Tutorial: Selected Value in Power BI.

The function selected value returns the value of the column reference passed as first argument if it is the only value available in the filter context, otherwise it returns blank or the default value passed as the second argument.

What is the Selected Value?

The selected value is a DAX function that returns the value of a column in a table that has been filtered by a slicer or a filter. It is often used in combination with other DAX functions to perform calculations or create dynamic visualizations.

When a slicer or filter is applied to a Power BI report, it restricts the data displayed in the visualizations based on the selected values. The selected value function allows you to reference the filtered values and perform calculations or create measures based on those values.

Using the Selected Value Function

To use the selected value function in Power BI, you need to follow these steps:

  1. Create a slicer or filter in your Power BI report.
  2. Select the desired values in the slicer or filter.
  3. In the DAX formula bar, type the selected value function followed by the column name in square brackets.
  4. Press Enter to calculate the selected value.

For example, let’s say you have a sales report with a slicer for product categories. You want to create a measure that calculates the total sales for the selected category. You can use the selected value function in the following way:

Total Sales = CALCULATE(SUM(Sales[Amount]), Sales[Category] = SELECTEDVALUE('Product'[Category]))

In this example, the selected value function (SELECTEDVALUE) is used to filter the sales data based on the selected category in the slicer. The calculated measure (Total Sales) will display the total sales amount for the selected category.

Considerations when using the Selected Value Function

When using the selected value function in Power BI, there are a few considerations to keep in mind:

  • The selected value function can only be used with single-column tables or columns.
  • If there are multiple values selected in the slicer or filter, the selected value function will return an error.
  • If there are no values selected in the slicer or filter, the selected value function will return blank.
  • The selected value function can be used in measures, calculated columns, or calculated tables.

It’s important to note that the selected value function is just one of the many functions available in Power BI DAX. It can be combined with other DAX functions to create more complex calculations and expressions.

Conclusion

The selected value function in Power BI DAX is a powerful tool that allows you to reference the filtered values in your reports and perform calculations or create dynamic visualizations. By understanding how to use the selected value function, you can enhance your Power BI reports and gain deeper insights into your data.

Leave a Comment