Article

DAX Language - COUNT and COUNTX

DAX Language - COUNT and COUNTX


A.Baddane | Posted on April 09, 21

COUNT Function

 Description:

The COUNT function counts the number of non blank cells in a column.

 Return Value:

COUNT returns a whole number, that is the number of non blank cells in the column.

 Syntax:

COUNT( <ColumnName> ) 
  • Description of the parameter:

 

PARAMETER

DESCRIPTION

ColumnName

Column that contains the values to be counted

 

 Example:

  The following example counts the number of values in the column ContinentName.

Number_Continent = COUNT( Geography[ContinentName] )

The COUNT function accepts a column as argument only, and that contains numbers, dates or strings values.


 

COUNTX Function

 Description:

The COUNTX function counts the number of rows that contain a non-blank value when evaluating an expression over a table.

 Return Value:

COUNTX returns an integer value, result of the count.

 Syntax:

COUNTX( <Table>,<Expression> )
  • Description of the parameters:

 

PARAMETER

DESCRIPTION

Table

The table containing the rows to be counted

Expression

The expression to be evaluated for each row of the table.

 

 Example:

To calculate the number of rows in the Product table of type "Televisions", and which have a Unit price, we can use the following formula:

Measure =
        COUNTX(
            FILTER('Product',
                RELATED(ProductSubcategory[ProductSubcategory])="Televisions"
                ),
            'Product'[UnitPrice]
            )

This formula passes a filtered table to COUNTX for the first argument. Using FILTER and RELATED functions, we will return all products whose sub category is Televisions, and then counts the rows in the resulting table that have a list price.

The first argument of the COUNTX 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.

 

  • COUNT and COUNTX return a blank if there are no rows to count. 
  • TRUE/FALSE values are not supported

 

Related Video:

 


(0) Comments

There is no comment

Leave a Comment
Add to favorite
Categories
Recent Posts
Filter column based on a list in Power Query
A.Baddane | April 05, 23

Sometimes when you work within power query, you need to filt...Read More


Use HTML in Power BI - Part 2
A.Baddane | July 05, 22

In the first blog post about using HTML in Power BI Desktop,...Read More


Use HTML in Power BI
A.Baddane | Feb. 21, 22

In this blog post, I will show you how to use HTML to create...Read More


Covid-19 Report
A.Baddane | Nov. 23, 21

The COVID-19 pandemic, also known as the coronavirus pandemi...Read More