HASONEFILTER DAX Function (Information)
Returns true when the specified table or column has one and only one value resulting from direct filter(s).
Syntax
| Parameter | Attributes | Description |
|---|---|---|
| ColumnName |
The column to check the filter info. |
Return values
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.
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