DAX COUNTX Function

Get last date in the current context in DAX.

COUNTX is an iterator function in DAX that:

  • Iterates over a table
  • Evaluates an expression for each row
  • Counts how many of those evaluated results are non-blank

Syntax

COUNTX(<table>, <expression>)
  • <table>: A real or virtual table to iterate over
  • <expression>: The expression to evaluate for each row (usually a column, but can be more complex)

Example

Let’s say you have a Sales table:

ProductQuantityDiscount
A25
B3(blank)
C110
D40

You want to count how many sales have a non-blank discount.

COUNTX(Sales, Sales[Discount])
  • Step-by-step:
RowSales[Discount]Counted?
A5
BBLANK()
C10
D0

Result = 3

  • It counts 0 as a valid number (because it's not blank).
  • It does NOT count blank values.

How is it Different from COUNT?

FunctionBehavior
COUNTCounts the number of non-blank values in a column only
COUNTXEvaluates an expression row-by-row, counts non-blanks

When to Use COUNTX

Use COUNTX when:

  • You need to evaluate a row-level expression, and count how many results are not blank
  • You're using a virtual table (like with FILTER, SUMMARIZE, etc.)
  • You want to do conditional counting without writing a full CALCULATE + FILTER formula

Example

  • Count Orders with Discount > 0
COUNTX(
    FILTER(Sales, Sales[Discount] > 0),
    Sales[Discount]
)
  • This counts how many rows have a discount greater than 0
  • It ignores 0 and blank values

Summary

FeatureCOUNTX
Function TypeIterator
EvaluatesRow-by-row expression
CountsOnly non-blank results
Use with filters?✅ Yes works great with FILTER, VALUES, etc.
No questions available.