Dax Function: SELECTEDVALUE

Category: Filter Functions

The SELECTEDVALUE function in Power BI is a DAX function used to retrieve the value of a column when a single value is selected in a filter context. If multiple values are selected, it returns a specified alternate result or BLANK.

Purpose

  • Dynamic Value Retrieval: Fetches a single value based on current filter context.

  • Conditional Logic: Returns a specific value or an alternate result when multiple or no values are selected.

  • Enhancing Reports: Provides user-friendly, context-sensitive information in visuals.

Type of Calculations

  • Scalar Calculation: Returns a scalar value from a column.

  • Context-Dependent Output: Adapts based on slicer or filter conditions.

Practical Use Cases

  1. Dynamic Titles: Display a title based on selected slicer values.

  2. Conditional Measures: Adjust measures based on the selected value.

  3. Filtering Logic: Simplify complex filter-based calculations.


SELECTEDVALUE(ColumnName [, AlternateResult])

ParameterTypeDescription
ColumnNameColumnThe column from which a value is retrieved.
AlternateResultScalarThe value to return if multiple values or no values are selected. Default is BLANK.

How Does SELECTEDVALUE Dax Works

  • Single Value Context: SELECTEDVALUE retrieves the column’s value when a single row is in the filter context.

  • Multiple Value Context: It evaluates the condition and returns the specified alternate result or BLANK.

Logical Formula:

IF(HASONEVALUE(ColumnName), VALUES(ColumnName), AlternateResult)

What Does It Return?

  • Single Value: Returns the value from the specified column if only one value is selected.

  • Alternate Result: Returns the alternate result if multiple or no values are selected.

When Should We Use It?

  • For Slicers: Retrieve the selected slicer value for use in titles or calculations.

  • Dynamic Logic: Use in measures to create conditional outputs based on user interactions.

  • Error Handling: Safely handle cases with multiple selections in reports.

Examples

Basic Usage :

Retrieve the selected value from a Category column:


Selected Category = SELECTEDVALUE(Sales[Category])

With Alternate Result

Include a fallback message:


Selected Category = SELECTEDVALUE(Sales[Category], "Multiple Categories Selected")

Advanced Usage

Combine with measures to create dynamic calculations:


Revenue Based on Selection =
IF(
SELECTEDVALUE(Sales[Category]) = "Electronics",
SUM(Sales[Amount]) * 1.1, -- Apply a 10% boost for electronics
SUM(Sales[Amount])
)

Tips and Tricks

  1. Default Values: Use the AlternateResult parameter to handle unexpected contexts gracefully.

  2. Title Creation: Use in combination with text functions for dynamic report titles.

  3. Avoid Complex Filters: Simplify multi-condition filters with SELECTEDVALUE.

Performance Impact of SELECTEDVALUE DAX Function:

  • Efficient: SELECTEDVALUE is lightweight and performs well on large datasets.

  • Filter Context: Ensure proper context for expected results, especially with multiple filters.

Related Functions You Might Need

  • HASONEVALUE: Checks if only one value exists in the filter context.

  • VALUES: Returns all unique values from a column.

  • LOOKUPVALUE: Retrieves values based on conditions.

  • ISFILTERED: Checks if a column is filtered.

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

Unlock the full capabilities of Power BI and elevate your data insights with our specialized consulting services. Whether you need guidance on advanced DAX functions like those highlighted here, support in designing interactive dashboards, or expertise in optimizing data models for enhanced performance, our experienced Power BI consultants are equipped to deliver customized solutions for your business. Explore our Power BI Consulting Services page to discover how we can help your organization make smarter, data-driven decisions.

1. What does SELECTEDVALUE return if multiple values are selected?

It returns the alternate result or BLANK if no alternate is specified.

2. Can SELECTEDVALUE work without slicers?

Yes, it depends on the filter context, which can come from slicers, filters, or relationships.

3. How to handle multiple selections in SELECTEDVALUE?

Use the AlternateResult parameter to specify a fallback value.

4. Is SELECTEDVALUE efficient for large datasets?

Yes, it is optimized for scalar calculations and performs efficiently.

5. Can SELECTEDVALUE be used in calculated columns?

No, it is designed for measures and requires a dynamic filter context.