APPROXIMATEDISTINCTCOUNT DAX Function (Aggregation)

Returns an estimated count of the unique values in a column. The function is optimized for query performance, but the result is slightly less accurate than DISTINCTCOUNT.

Syntax

APPROXIMATEDISTINCTCOUNT ( <ColumnName> )
Parameter Attributes Description
ColumnName

The column for which the distinct values are counted.

Return values

Scalar A single integer value.

The approximate number of distinct values in ColumnName.

Remarks

ColumnName must be a column reference. An expression returns an error.

The function returns BLANK when there are no rows to count.

In DirectQuery mode, the function sends a corresponding aggregation to the data source. The supported data sources are Azure SQL, Azure Synapse dedicated SQL pool, BigQuery, Databricks, and Snowflake. On Azure SQL, the generated SQL query uses APPROX_COUNT_DISTINCT. Direct Lake on SQL also uses this behavior when it falls back to DirectQuery.

In Import mode and in Direct Lake mode without fallback, the engine computes the estimate with a HyperLogLog algorithm. Support for these modes is in preview. Microsoft reports an error rate of about 1.6% for these modes.

Use APPROXIMATEDISTINCTCOUNT for high-cardinality columns when an approximate result is good enough. Use DISTINCTCOUNT when you need an exact result. On low-cardinality columns, APPROXIMATEDISTINCTCOUNT can be slower and use more memory than DISTINCTCOUNT.

» 2 related functions

Examples

-- APPROXIMATEDISTINCTCOUNT returns an estimate of the number of distinct values.
-- In DirectQuery mode, the data source computes the estimate.
-- In Import and Direct Lake mode (preview), the engine computes it
-- with a HyperLogLog algorithm.
-- For small counts, the estimate can be equal to the exact DISTINCTCOUNT.
DEFINE
    MEASURE Sales[#Prods] = DISTINCTCOUNT ( Sales[ProductKey] )
    MEASURE Sales[#App Prods] = APPROXIMATEDISTINCTCOUNT ( Sales[ProductKey] )
EVALUATE
SUMMARIZECOLUMNS (
    'Date'[Calendar Year],
    TREATAS ( { "CY 2007", "CY 2008", "CY 2009" }, 'Date'[Calendar Year] ),
    "#Prods", [#Prods],
    "#App Prods", [#App Prods]
)
ORDER BY 'Date'[Calendar Year]
Calendar Year #Prods #App Prods
CY 2007 1258 1258
CY 2008 1478 1478
CY 2009 1513 1513

Related functions

Other related functions are:

Last update: Oct 28, 2026   » Contribute   » Show contributors

Contributors: Alberto Ferrari, Marco Russo, Kenneth Barber

Microsoft documentation: https://docs.microsoft.com/en-us/dax/approximate-distinctcount-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 APPROXIMATEDISTINCTCOUNT? 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.