SELECTEDVALUE DAX Function (Filter)

Returns the value when there’s only one value in the specified column, otherwise returns the alternate result.

Syntax

SELECTEDVALUE ( <ColumnName> [, <AlternateResult>] )
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

Scalar A single value of any type.

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>)
» 3 related articles
» 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:

Related functions

Other related functions are:

Last update: May 12, 2021   » Contribute   » Show contributors

Contributors: Alberto Ferrari, Marco Russo

Microsoft documentation: https://docs.microsoft.com/en-us/dax/selectedvalue-function

2018-2021 © SQLBI. All rights are reserved. Information coming from Microsoft documentation is property of Microsoft Corp. » Contact us   » Privacy Policy & Cookies

Context Transition

This function performs a Context Transition if called in a Row Context. Click to read more.

Row Context

This expression is executed in a Row Context. Click to read more.

Iterator

Not recommended

The use of this function is not recommended. See Remarks and Related functions for alternatives.

Not recommended

The use of this parameter is not recommended.

Deprecated

This function is deprecated. Jump to the Alternatives section to see the function to use.

Deprecated

This parameter is deprecated and its use is not recommended.

DirectQuery compatibility

Limitations are placed on DAX expressions allowed in measures and calculated columns.
The state below shows the DirectQuery compatibility of the DAX function.

Contribute

Want to improve the content of SELECTEDVALUE? Did you find any issue?
Please, report it us! All submissions will be evaluated for possible updates of the content.


This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.