DISTINCTCOUNT DAX Function (Aggregation)
Counts the number of distinct values in a column.
Syntax
Parameter | Attributes | Description |
---|---|---|
ColumnName |
The column for which the distinct values are counted. |
Return values
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] ) )
» 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
Learn more about DISTINCTCOUNT in the following 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: Dec 4, 2024 » Contribute » Show contributors
Contributors: Alberto Ferrari, Marco Russo
Microsoft documentation: https://docs.microsoft.com/en-us/dax/distinctcount-function-dax