SELECTEDVALUE

Updated on

SELECTEDVALUE is a DAX function that returns the value when there is only one distinct value in a specified column; otherwise, it returns an alternate result.

Syntax

SELECTEDVALUE(
   ColumnName,
   AlternateResult
)
Argument Properties Description
ColumnName The column from which a single value is to be returned.
AlternateResult Optional The value that is returned when there is no value or more than one value in the specified column; if omitted, BLANK is returned.

Return Values

The value when the context for columnName has been filtered down to one distinct value only. Else, alternateResult.

Remarks

  • An equivalent expression for SELECTEDVALUE(<columnName>, <alternateResult>) is IF(HASONEVALUE(<columnName>), VALUES(<columnName>), <alternateResult>).

  • To learn more about best practices when using SELECTEDVALUE, see Use SELECTEDVALUE instead of VALUES in DAX.

  • This function is not supported for use in DirectQuery mode when used in calculated columns or row-level security (RLS) rules.

Example

The following DAX query:

DEFINE
 MEASURE DimProduct[Selected Color] = SELECTEDVALUE(DimProduct[Color], "No Single Selection")
EVALUATE
 SUMMARIZECOLUMNS
   (ROLLUPADDISSUBTOTAL(DimProduct[Color], "Is Total"),
   "Selected Color", [Selected Color])ORDER BY [Is Total] ASC,
   [Color] ASC

Returns the following:

DimProduct[Color] [Is Total] [Selected Color]
Black FALSE Black
Blue FALSE Blue
Grey FALSE Grey
Multi FALSE Multi
NA FALSE NA
Red FALSE Red
Silver FALSE Silver
Silver/Black FALSE Silver/Black
White FALSE White
Yellow FALSE Yellow
TRUE No Single Selection

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/dax/selectedvalue-function-dax

2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy