Code action DR009
(Readability) Rewrite using DISTINCTCOUNT
Description
Instead of using a combination of COUNTROWS
and DISTINCT
to count the number of distinct values in a column, use the DISTINCTCOUNT
function.
Example
Change:
COUNTROWS(DISTINCT(Sales[CalendarDate]))
To:
```dax
DISTINCTCOUNT(Sales[CalendarDate])
Why is Tabular Editor suggesting this?
While both options produce the same result and the same query plan (i.e. identical performance), the DISTINCTCOUNT
function is more concise and easier to read than the combination of COUNTROWS
and DISTINCT
. By using DISTINCTCOUNT
, the code becomes more readable and the intent of the expression is clearer.