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:

Note: An equivalent expression for SELECTEDVALUE(ColumnName, AlternateResult) is IF(HASONEVALUE(ColumnName), VALUES(columnName), AlternateResult).

Example: Let’s create a measure “SELECTEDVALUE Measure”.

DAX

SELECTEDVALUE Measure = SELECTEDVALUE(Sheet1[Country])

The output of the above measure is shown below:

SELECTEDVALUE dax function in Power BI

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.

SELECTEDVALUE dax function in Power BI

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

SELECTEDVALUE dax function in Power BI

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

SELECTEDVALUE dax function in Power BI

Also create a new table with name Class by using the table constructor.

DAX

Class = {"10th", "12th"}

The output of the above dax expression is shown below:

SELECTEDVALUE dax function in Power BI

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:

SELECTEDVALUE dax function in Power BI