HASONEFILTER DAX Function (Information)

Returns true when the specified table or column has one and only one value resulting from direct filter(s).

Syntax

HASONEFILTER ( <ColumnName> )
Parameter Attributes Description
ColumnName

The column to check the filter info.

Return values

Scalar A single boolean value.

TRUE when the number of directly filtered values on ColumnName is one; otherwise returns FALSE.

Remarks

This function is similar to HASONEVALUE with the difference that HASONEVALUE works based on cross-filters while HASONEFILTER works by a direct filter.

HASONEFILTER corresponds to the following code:

COUNTROWS ( FILTERS ( <ColumnName> ) ) = 1

HASONEFILTER does not count the filter values that do not exist in ColumnName. If a filter has only values that do not exist, HASONEFILTER returns FALSE.

A filter on a table filters all the columns of the table directly. For example, with FILTER ( ‘Product’, ‘Product'[Product Name] = “Contoso 512MB MP3 Player E51 Silver” ) as a filter argument of CALCULATE, HASONEFILTER ( ‘Product'[Brand] ) returns TRUE. With a filter on the Product Name column only, it returns FALSE.

If ColumnName has only one value in the model, HASONEFILTER returns TRUE also when there is no filter. The reason is that FILTERS returns all the values of a column that has no filter. To check if a column has a filter, use ISFILTERED.

A row context is not a filter. To use the current row as a filter, use CALCULATE, which does a context transition.

ColumnName must be a column reference. A table or an expression returns an error.

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

» 2 related functions

Examples

--  HASONEFILTER checks whether a column is being filtered
--  with only one value.
--
--  Filters on non-existing values are not considered
DEFINE
    MEASURE Sales[Audio only] =
        CALCULATE (
            HASONEFILTER ( 'Product'[Category] ),
            'Product'[Category] = "Audio"
        )
    MEASURE Sales[Audio and computers] =
        CALCULATE (
            HASONEFILTER ( 'Product'[Category] ),
            'Product'[Category] IN { "Audio", "Computers" }
        )
    MEASURE Sales[Audio and bananas] =
        CALCULATE (
            HASONEFILTER ( 'Product'[Category] ),
            'Product'[Category] IN { "Audio", "Bananas" }
        )
EVALUATE
{
     ( "Audio only", [Audio only] ),
     ( "Audio and computers", [Audio and computers] ),
     ( "Audio and bananas", [Audio and bananas] )
}
Value1 Value2
Audio only true
Audio and computers false
Audio and bananas true
--  HASONEFILTER is not HASONEVALUE.
--  A column can have only one value visible because of
--  cross-filtering.
DEFINE
    MEASURE Sales[Has One Filter] =
        CALCULATE (
            HASONEFILTER ( 'Product'[Category] ),
            'Product'[Product Name] = "Contoso 512MB MP3 Player E51 Silver"
        )
    MEASURE Sales[Has One Value] =
        CALCULATE (
            HASONEVALUE ( 'Product'[Category] ),
            'Product'[Product Name] = "Contoso 512MB MP3 Player E51 Silver"
        )
EVALUATE
{
     ( "Has One Filter", [Has One Filter] ),
     ( "Has One Value", [Has One Value] )
}
Value1 Value2
Has One Filter false
Has One Value true
--  A column can be filtered without showing any values,
--  because of cross-filters
DEFINE
    MEASURE Sales[Has One Filter] =
        CALCULATE (
            HASONEFILTER ( 'Product'[Category] ),
            'Product'[Category] = "Home Appliances",
            'Product'[Product Name] = "Contoso 512MB MP3 Player E51 Silver"
        )
    MEASURE Sales[Are there any products?] =
        CALCULATE (
            COUNTROWS ( 'Product' ) > 0,
            'Product'[Category] = "Home Appliances",
            'Product'[Product Name] = "Contoso 512MB MP3 Player E51 Silver"
        )
EVALUATE
{
     ( "Has One Filter", [Has One Filter] ),
     ( "Are there any products?", [Are there any products?] )
}
Value1 Value2
Has One Filter true
Are there any products? false
-- HASONEFILTER counts the values in FILTERS.
-- A filter on the table (FILTER over 'Product') filters all the columns
-- of the table directly, so Brand has a direct filter with one value.
-- A column with only one value returns TRUE also without filters,
-- because FILTERS returns all the values of a column that has no filter.
-- A filter on a value that does not exist is not considered.
-- A row context is not a filter: CALCULATE does a context transition.
DEFINE
    VAR ProductName = "Contoso 512MB MP3 Player E51 Silver"
EVALUATE
SELECTCOLUMNS (
    {
        ( 1, "Filter on the Product Name column",
            CALCULATE ( HASONEFILTER ( 'Product'[Brand] ), 'Product'[Product Name] = ProductName ) ),
        ( 2, "Filter on the Product table",
            CALCULATE ( HASONEFILTER ( 'Product'[Brand] ), FILTER ( 'Product', 'Product'[Product Name] = ProductName ) ) ),
        ( 3, "Column with one value, no filter",
            HASONEFILTER ( Sales[CurrencyKey] ) ),
        ( 4, "ISFILTERED on the same column",
            ISFILTERED ( Sales[CurrencyKey] ) ),
        ( 5, "Filter on a value that does not exist",
            CALCULATE ( HASONEFILTER ( 'Product'[Color] ), 'Product'[Color] = "Bananas" ) )
    },
    "#", [Value1],
    "Test", [Value2],
    "Result", [Value3]
)
ORDER BY [#]

EVALUATE
ADDCOLUMNS (
    TOPN ( 2, VALUES ( 'Product'[Color] ), 'Product'[Color], ASC ),
    "Row context", HASONEFILTER ( 'Product'[Color] ),
    "Context transition", CALCULATE ( HASONEFILTER ( 'Product'[Color] ) )
)
ORDER BY 'Product'[Color]
# Test Result
1 Filter on the Product Name column False
2 Filter on the Product table True
3 Column with one value, no filter True
4 ISFILTERED on the same column False
5 Filter on a value that does not exist False
Color Row context Context transition
Azure False True
Black False True

Related functions

Other related functions are:

Last update: Nov 26, 2026   » Contribute   » Show contributors

Contributors: Alberto Ferrari, Marco Russo

Microsoft documentation: https://learn.microsoft.com/en-us/dax/hasonefilter-function-dax

2018-2026 © 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.

Passed by Expression

This parameter is passed by expression and can be evaluated multiple times in different evaluation contexts.

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.

Volatile

A volatile function may return a different result every time you call it, even if you provide the same arguments. Click to read more.

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 HASONEFILTER? Did you find any issue?
Please, report it us! All submissions will be evaluated for possible updates of the content.