Dataset: https://github.com/slidescope/data/blob/master/DAX_Count_Functions_Demo.csv
Here are example DAX formulas using the dataset for understanding COUNT, COUNTA, COUNTX, and COUNTAX in Power BI:
Make sure some blanks are there
CleanedUnits = IF(‘TableName'[UnitsSold] = 0, BLANK(), ‘TableName'[UnitsSold])
🧮 1. COUNT
Counts only non-blank numeric values in a single column.
Count_ProductID = COUNT('TableName'[ProductID])
🟡 Explanation: This counts all non-empty numeric values in the ProductID column. It will ignore blanks.
🧾 2. COUNTA
Counts non-blank values of any data type in a single column (text, number, etc.).
CountA_ProductName = COUNTA('TableName'[ProductName])
🟡 Explanation: Counts all non-blank values in ProductName, including strings like "" (empty string).
📊 3. COUNTX
Iterates over a table and counts non-blank results from an expression.
CountX_UnitsSold_NotBlank = COUNTX('TableName', 'TableName'[UnitsSold])
🟡 Explanation: For each row in TableName, it checks if UnitsSold is not blank and counts those.
🧠 4. COUNTAX
Like COUNTX, but used when expression is evaluated on a related table or using complex expressions.
CountAX_UnitsRevenue = COUNTAX('TableName', 'TableName'[UnitsSold] * 'TableName'[UnitPrice])
🟡 Explanation: This evaluates the expression UnitsSold * UnitPrice for each row, and counts how many times it returns a non-blank result.
Optional Measures to Show:
Revenue (for comparison)
Revenue = SUMX('TableName', 'TableName'[UnitsSold] * 'TableName'[UnitPrice])
