COUNT DAX Function (Aggregation)

Counts the number of rows in the table where the specified column has a non-blank value.

Syntax

COUNT ( <ColumnName> )
Parameter Attributes Description
ColumnName

The column that contains the values to be counted.

Return values

Scalar A single integer value.

Returns the number of cells in a column that contain a non blank value.

Remarks

The only argument allowed to this function is a column.

When the function finds no rows that are non-blank, it returns a blank.

COUNT and COUNTA are identical in DAX for all the data types except Boolean. COUNTA can operate on a Boolean data type, whereas COUNT cannot do that.

The COUNT function internally executes COUNTX, without any performance difference.
The following COUNT call:

COUNT ( table[column] )

corresponds to the following COUNTX call:

COUNTX (
    table,
    table[column]
)
» 1 related function

Examples

--  COUNT is the short version of COUNTX, when used with one column only
--  In DAX, there are no differences between COUNTA and COUNT
--  COUNTX can be expressed in a more explicit way by using CALCULATE
--  and COUNTROWS
DEFINE
    MEASURE Customer[# Customers]     = COUNTROWS ( Customer )
    MEASURE Customer[# Individuals 1] = COUNT ( Customer[Customer Name] )
    MEASURE Customer[# Individuals 2] = COUNTX ( Customer, Customer[Customer Name] )
    MEASURE Customer[# Individuals 3] =
        CALCULATE ( 
            COUNTROWS ( Customer ), 
            NOT ISBLANK ( Customer[Customer Name] ) 
        )
EVALUATE
SUMMARIZECOLUMNS (
    Customer[Continent],
    "# Customers",     [# Customers],
    "# Individuals 1", [# Individuals 1],
    "# Individuals 2", [# Individuals 2],
    "# Individuals 3", [# Individuals 3]
)
Continent # Customers # Individuals 1 # Individuals 2 # Individuals 3
Asia 3,658 3,624 3,624 3,624
North America 9,665 9,527 9,527 9,527
Europe 5,546 5,525 5,525 5,525
--  COUNT does not count blanks, but it counts empty strings
--  using the CALCULATE version, the code is clearer
DEFINE
    MEASURE Customer[# COUNT] = COUNT ( Customer[Customer Name] )
    MEASURE Customer[# NO BLANKS] =
        CALCULATE ( 
            COUNTROWS ( Customer ), 
            NOT ISBLANK ( Customer[Customer Name] ) 
        )
    MEASURE Customer[# NO BLANKS / EMPTY STRINGS] =
        CALCULATE ( 
            COUNTROWS ( Customer ), 
            Customer[Customer Name] <> "" 
        )
EVALUATE
SUMMARIZECOLUMNS (
    Customer[Continent],
    "# COUNT", [# COUNT],
    "# NO BLANKS", [# NO BLANKS],
    "# NO BLANKS / EMPTY STRINGS", [# NO BLANKS / EMPTY STRINGS]
)

Continent # COUNT # NO BLANKS # NO BLANKS / EMPTY STRINGS
Asia 3,624 3,624 3,591
North America 9,527 9,527 9,389
Europe 5,525 5,525 5,504

Related functions

Other related functions are:

Last update: Oct 3, 2024   » Contribute   » Show contributors

Contributors: Alberto Ferrari, Marco Russo

Microsoft documentation: https://docs.microsoft.com/en-us/dax/count-function-dax

2018-2024 © SQLBI. All rights are reserved. Information coming from Microsoft documentation is property of Microsoft Corp. » Contact us   » Privacy Policy & Cookies

Context Transition

This function performs a Context Transition if called in a Row Context. Click to read more.

Row Context

This expression is executed in a Row Context. Click to read more.

Iterator

Not recommended

The use of this function is not recommended. See Remarks and Related functions for alternatives.

Not recommended

The use of this parameter is not recommended.

Deprecated

This function is deprecated. Jump to the Alternatives section to see the function to use.

Volatile

A volatile function may return a different result every time you call it, even if you provide the same arguments. Click to read more.

Deprecated

This parameter is deprecated and its use is not recommended.

DirectQuery compatibility

Limitations are placed on DAX expressions allowed in measures and calculated columns.
The state below shows the DirectQuery compatibility of the DAX function.

Contribute

Want to improve the content of COUNT? Did you find any issue?
Please, report it us! All submissions will be evaluated for possible updates of the content.


This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.