# DISTINCTCOUNTDAX Function (Aggregation)

Counts the number of distinct values in a column.

## Syntax

DISTINCTCOUNT ( <ColumnName> )
Parameter Attributes Description
ColumnName

The column for which the distinct values are counted.

## Return values

Scalar A single integer value.

The number of distinct values in ColumnName.

## Remarks

The only argument allowed to this function is a column. You can use columns containing any type of data. When the function finds no rows to count, it returns a BLANK, otherwise it returns the count of distinct values.

The syntax:

```DISTINCTCOUNT ( table[column] )
```

corresponds to:

```COUNTROWS ( DISTINCT ( table[column] ) )
```
» 3 related articles
» 4 related functions

## Examples

```--  DISTINCTCOUNT counts the number of distinct values in a column
DEFINE
MEASURE Customer[# Customers] = COUNTROWS ( Customer )
MEASURE Customer[# Names] =
DISTINCTCOUNT ( Customer[Name] )
MEASURE Customer[# Countries 1] =
DISTINCTCOUNT ( Customer[CountryRegion] )
MEASURE Customer[# Countries 2] =
COUNTROWS ( DISTINCT ( Customer[CountryRegion] ) )
EVALUATE
SUMMARIZECOLUMNS (
Customer[Continent],
"# Customers", [# Customers],
"# Names", [# Names],
"# Countries 1", [# Countries 1],
"# Countries 2", [# Countries 2]
)
```
Continent # Customers # Names # Countries 1 # Countries 2
Asia 3,658 3,583 15 15
North America 9,665 9,355 2 2
Europe 5,546 5,501 12 12
```--
--  DISTINCTCOUNT considers BLANK as a valid value, whereas
--  DISTINCTCOUNTNOBLANK does not count any blank value
--
DEFINE
MEASURE Customer[# Stores] =
COUNTROWS ( Store )
MEASURE Customer[# Manager] =
DISTINCTCOUNT ( Store[Area Manager] )
MEASURE Customer[# Manager (no blank)] =
DISTINCTCOUNTNOBLANK ( Store[Area Manager] )
MEASURE Customer[# Stores without manager] =
COUNTBLANK ( Store[Area Manager] )
EVALUATE
SUMMARIZECOLUMNS (
Store[Continent],
"# Stores", [# Stores],
"# Manager", [# Manager],
"# Manager (no blank)", [# Manager (no blank)],
"# Stores without manager", [# Stores without manager]
)
ORDER BY
Store[Continent]
```
Continent # Stores # Manager # Manager (no blank) # Stores without manager
Asia 41 5 5 (Blank)
Europe 54 8 7 7
North America 209 40 39 5

## Related articles

• Related Distinct Count

The Related Distinct Count pattern allows you to apply the distinct count calculation to any column in any table in the data model. Instead of just counting the number of distinct count values in the entire table using only the DISTINCTCOUNT function, the pattern filters only those values related to events filtered in another table. » Read more

• Analyzing the performance of DISTINCTCOUNT in DAX

This article describes how to analyze the performance of a DAX measure based on a DISTINCTCOUNT calculation and how to evaluate possible optimizations. » Read more

• Why Power BI totals might seem inaccurate

A common question is why Power BI totals are inaccurate because they do not display the sum of individual rows. In this article, we explain the reasons why those totals are correct. » Read more

## Related functions

Other related functions are:

Last update: Sep 5, 2024     » Show contributors

Contributors: Alberto Ferrari, Marco Russo

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

# 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.

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