SELECTEDVALUE DAX Function (Filter)
Returns the value when there’s only one value in the specified column, otherwise returns the alternate result.
Syntax
Parameter | Attributes | 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
A similar expression for
SELECTEDVALUE( <columnName>, <alternateResult>)
is
IF(HASONEVALUE(<columnName>), VALUES(<columnName>), <alternateResult>)
» 2 related functions
Examples
SELECTEDVALUE returns the value currently visible in the filter context for a column if there is only one value filtered. Otherwise, it returns the default argument.
-- Shows "unknown" when there are more values in the filter context -- for the columns specified in the first argument of SELECTEDVALUE EVALUATE CALCULATETABLE ( SUMMARIZECOLUMNS ( Product[Brand], ROLLUPADDISSUBTOTAL ( 'Product'[Category], "Total Category" ), "Current Brand", SELECTEDVALUE ( 'Product'[Brand], "**Unknown Brand**" ), "Current Category", SELECTEDVALUE ( 'Product'[Category], "**Unknown Category**" ), "Current Product", SELECTEDVALUE ( 'Product'[Product Name], "**Unknown Product**" ) ), TREATAS ( { "Litware", "A. Datum" }, Product[Brand] ) )
Product[Brand] | Product[Category] | Total Category | Current Brand | Current Category | Current Product |
---|---|---|---|---|---|
Litware | TV and Video | false | Litware | TV and Video | **Unknown Product** |
A. Datum | Cameras and camcorders | false | A. Datum | Cameras and camcorders | **Unknown Product** |
Litware | Home Appliances | false | Litware | Home Appliances | **Unknown Product** |
Litware | (Blank) | true | Litware | **Unknown Category** | **Unknown Product** |
A. Datum | (Blank) | true | A. Datum | Cameras and camcorders | **Unknown Product** |
-- SELECTEDVALUE is equivalent to a more complex combination -- with HASONEVALUE and VALUES. EVALUATE SUMMARIZECOLUMNS ( 'Product'[Brand], "Current Brand", SELECTEDVALUE ( 'Product'[Brand], "**Unknown**" ), "Current Brand 2", IF ( HASONEVALUE ( 'Product'[Brand] ), VALUES ( 'Product'[Brand] ), "**Unknown**" ) )
Product[Brand] | Current Brand | Current Brand 2 |
---|---|---|
Contoso | Contoso | Contoso |
Wide World Importers | Wide World Importers | Wide World Importers |
Northwind Traders | Northwind Traders | Northwind Traders |
Adventure Works | Adventure Works | Adventure Works |
Southridge Video | Southridge Video | Southridge Video |
Litware | Litware | Litware |
Fabrikam | Fabrikam | Fabrikam |
Proseware | Proseware | Proseware |
A. Datum | A. Datum | A. Datum |
The Phone Company | The Phone Company | The Phone Company |
Tailspin Toys | Tailspin Toys | Tailspin Toys |
Related articles
Learn more about SELECTEDVALUE in the following articles:
-
Using the SELECTEDVALUE function in DAX
This article describes how the SELECTEDVALUE DAX function simplifies the syntax required in many scenarios where you need to read a single value selected in the filter context. » Read more
-
Showing the top 5 products and Other row
This article shows how to add an additional “other” row to the selection obtained using the Top N filter in a Power BI report. » Read more
-
Comparing with previous selected time period in DAX
This article describes how you can create a comparison with the previous time period in a visualization, regardless of whether the time periods are consecutive or not. » Read more
Related functions
Other related functions are:
Last update: Apr 2, 2021 » Contribute » Show contributors
Contributors: Alberto Ferrari, Marco Russo
Microsoft documentation: https://docs.microsoft.com/en-us/dax/selectedvalue-function