Dax Function: COUNTAX

Category: Aggregation functions

The COUNTAX function in Power BI is a DAX (Data Analysis Expressions) function that evaluates an expression for each row in a table and returns the count of non-blank results. It extends the functionality of the COUNTX function by supporting non-numeric columns and handling calculated results.

Purpose:

  • To count rows based on a calculated expression rather than a single column.
  • Useful for aggregating mixed data or conditional evaluations in a table.

Type of Calculations:

  • Iterative row-by-row evaluation of an expression.
  • Aggregates the count of rows where the evaluated result is not blank.

Practical Use Cases:

  1. Conditional Counts: Count rows based on specific conditions or calculated values.
  2. Survey Analysis: Count responses derived from calculated expressions.
  3. Data Validation: Verify non-blank results in complex scenarios.

COUNTAX(<table>, <expression>)</expression></table>

ParameterTypeDescription
tableTableThe table containing the data to evaluate.
expressionScalarThe expression to evaluate for each row. Results must be non-blank to be counted.

How Does COUNTAX Dax Function Works?

  1. Iterative Evaluation: The function iterates through each row in the specified table and evaluates the provided expression.
  2. Identify Non-Blank Results: It considers only non-blank results for the final count.
  3. Aggregate Count: The total number of non-blank results is returned.

Example:
If the table Sales has the following data:

ProductQuantityDiscount
A105%
B010%
C20 

COUNTAX(Sales, [Quantity] * (1 – [Discount])) will count rows where the evaluated discount price is non-blank.


What Does It Return?

The COUNTAX function returns a numeric scalar value representing the count of non-blank results generated by evaluating the expression for each row in the table.

When Should We Use It?

  • Custom Evaluations: When you need to count rows based on a calculated condition.
  • Mixed Data: For datasets containing non-numeric or mixed data types in the calculated expression.
  • Dynamic Counts: When counts depend on dynamic expressions like mathematical operations or logical comparisons.

Examples

Basic Usage

Count non-blank results for the column [Profit]:


TotalNonBlankProfits = COUNTAX(Sales, [Profit])

Output:Returns the count of non-blank rows in the Profit column.

Column Usage

Count rows where the Revenue exceeds 1000:


HighRevenueCount = COUNTAX(Sales, IF(Sales[Revenue] &gt; 1000, Sales[Revenue]))

Counts rows where revenue is greater than 1000.

Advanced Usage

Combine with CALCULATE to apply filters before counting:


FilteredCount = CALCULATE(COUNTAX(Sales, Sales[Quantity] * (1 - Sales[Discount])), Sales[Region] = "East")

Result: Counts rows with non-blank discount-adjusted quantities for the “East” region.

Tips and Tricks

  • Optimize for Performance: Avoid overly complex expressions in large datasets as row-by-row evaluation can be resource-intensive.
  • Handle Blank Results: Ensure your expression handles BLANK() values properly to avoid unexpected results.
  • Use in Measures: Apply COUNTAX within measures for better dynamic aggregations.

Performance Impact of COUNTAX DAX Function:

  • Row Iteration Overhead: COUNTAX can be slower for large tables due to iterative evaluation.
  • Optimizations: Use simpler expressions or filters to narrow the evaluated dataset.

Related Functions You Might Need

  • COUNT: Counts non-blank rows in numeric or text columns.
  • COUNTA: Counts all non-blank rows in a column, regardless of data type.
  • COUNTX: Similar to COUNTAX but optimized for numeric expressions.
  • COUNTBLANK: Counts the number of blank rows in a column.

Want to Learn More?
For more information, check out the official Microsoft documentation for COUNTAX. You can also experiment with this function in your Power BI reports to explore its capabilities.

If you’re looking to unlock the full potential of Power BI and take your data insights to the next level, our expert Power BI consulting services are here to help. Whether you need assistance with implementing advanced DAX functions like the ones discussed here, creating interactive dashboards, or optimizing your data models for better performance, our team of seasoned Power BI consultants is ready to provide tailored solutions for your business. Visit our Power BI Consulting page to learn more about how we can empower your organization with data-driven decisions.

1. What does the COUNTAX function do in Power BI?

The COUNTAX function counts the number of non-blank results from an evaluated expression for each row in a table.

2. How is COUNTAX different from COUNTX?

COUNTAX supports non-numeric expressions, while COUNTX is optimized for numeric calculations.

3. Can I use COUNTAX with filters?

Yes, COUNTAX can be combined with CALCULATE or other filtering functions to refine the count.

4. Does COUNTAX work on entire tables or just specific columns?

COUNTAX evaluates expressions row by row, so it works on columns within tables or calculated expressions derived from them.

5. Can COUNTAX handle errors in expressions?

If an expression produces an error, it will result in a blank and won’t be counted.