SELECTEDVALUE DAX Function in Power BI
The SELECTEDVALUE DAX function returns the value when the context for columnName has been filtered down to one distinct value only, otherwise returns an optional alternateResult if specified.
DAX Syntax SELECTEDVALUE(ColumnName) Or SELECTEDVALUE(ColumnName, AlternateResult)
The function has the following parameters:
- ColumnName: The name of an existing column, using standard DAX syntax. It cannot be an expression.
- AlternateResult: It is an optional parameter. The value returned when there is either no value or more than one value in the specified column (if omitted, the default value blank is returned).
Note: An equivalent expression for SELECTEDVALUE(ColumnName, AlternateResult) is IF(HASONEVALUE(ColumnName), VALUES(columnName), AlternateResult).
Example: Let’s create a measure “SELECTEDVALUE Measure”.
DAX
The output of the above measure is shown below:

In the image above we can see that value Blank is returned as Country value is not selected to only one value.
Let’s select any country value from the slicer. So now it is filtered down to one value, so we can see the value in the measure.

If we select multiple countries from the slicer, then we see that Blank is returned in SELECTEDVALUE function.

Example: Let’s we have the following data in the table named ‘Students Data’.

Also create a new table with name Class by using the table constructor.
DAX
The output of the above dax expression is shown below:

Let’s create a new measure named “Selected class Measure”.
DAX
Selected class Measure = SWITCH ( SELECTEDVALUE (Class[Value] ), "10th", SUM('Students Data'[10th_Marks]), "12th", SUM('Students Data'[12th_Marks]), SUM('Students Data'[10th_Marks]) + SUM('Students Data'[12th_Marks]) )
Explanation of Each Part:
- Selected class Measure: This is the name of the new measure being created.
- SWITCH Function: The SWITCH function evaluates the expression SELECTEDVALUE(Class[Value]) and matches it with the provided values.
- SELECTEDVALUE(Class[Value]): Retrieves the currently selected value from the Class[Value] column.
- "10th": If the selected value is "10th", it returns the calculation SUM('Students Data'[10th_Marks]).
- "12th": If the selected value is "12th", it returns the calculation SUM('Students Data'[12th_Marks]).
- SUM('Students Data'[10th_Marks]) + SUM('Students Data'[12th_Marks]): If the selected value is neither "10th" nor "12th", it defaults to returning the sum of 10th Marks and 12th Marks columns from the Students Data table.
