COUNTX

Updated on

COUNTX is a DAX function that counts the number of values resulting from evaluating an expression for each row of a table.

Syntax

COUNTX(
   Table,
   Expression
)
Argument Properties Description
Table The table containing the rows for which the expression will be evaluated.
Expression The expression to be evaluated for each row of the table.

Return Values

An integer.

Remarks

  • The COUNTX function takes two arguments. The first argument must always be a table, or any expression that returns a table. The second argument is the column or expression that is searched by COUNTX.

  • The COUNTX function counts only values, dates, or strings. If the function finds no rows to count, it returns a blank.

  • If you want to count logical values, use the COUNTAX function.

  • This function is not supported for use in DirectQuery mode when used in calculated columns or row-level security (RLS) rules.

Example 1

The following formula returns a count of all rows in the Product table that have a list price.

= COUNTX(Product,[ListPrice])

Example 2

The following formula illustrates how to pass a filtered table to COUNTX for the first argument. The formula uses a filter expression to get only the rows in the Product table that meet the condition, ProductSubCategory = “Caps”, and then counts the rows in the resulting table that have a list price. The FILTER expression applies to the table Products but uses a value that you look up in the related table, ProductSubCategory.

= COUNTX(FILTER(Product,RELATED(ProductSubcategory[EnglishProductSubcategoryName])="Caps"), Product[ListPrice])

Other functions related to COUNTX are:

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/dax/countx-function-dax

2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy