Skip to main content

Power BI

New

COUNTIF in DAX Language

Vote (8) Share
Jeroen Habets's profile image

Jeroen Habets on 17 Dec 2018 18:08:54

A COUNTIF is sorely missed in DAX.

(The workaround with CALCULATE and FILTER is too cumbersome and complex for most users)

Comments (2)
Jeroen Habets's profile image Profile Picture

5a09c956 9d3e-4112-9039-492d22b24fa0 on 06 Jul 2020 00:00:46

RE: COUNTIF in DAX Language

One of the beauties of DAX over Excel is that filtration (the "IF" or "IFS" step) is separated from the aggregation step (count, sum, average, minimum, etc.). Instead of introducing a new "IF" or "IFS" function for each type of aggregation (SUMIFS, MINIFS, etc.), you filter your data with FILTER and you use your normal aggregation function on that filtered table.

In DAX, the equivalent of COUNTIF would be this:
COUNTROWS(FILTER('Table',))

What is the workaround with CALCULATE and FILTER that you had in mind?

Jeroen Habets's profile image Profile Picture

c0607ca9 8c30-4c1d-bd80-94db118d54ec on 05 Jul 2020 23:37:43

RE: COUNTIF in DAX Language

You can use COUNTX instead. Btw, CALCULATE and FILTER are most-learn functions in POWER BI, do encourage the users to learn them.