COUNTROWS

How to Use the Power BI DAX function COUNTROWS

In this article, we will discuss how to use the Power BI DAX function COUNTROWS in detail, including its syntax and examples of its usage.

Syntax of the COUNTROWS Function

The syntax of the COUNTROWS function is straightforward. It takes a table or an expression that returns a table as its argument and returns the number of rows in the table. The general syntax for the COUNTROWS function is as follows:


COUNTROWS(❰table❱)


The following example demonstrates how to use the COUNTROWS function to count the number of rows in a table named 'Sales':


CountRowsSales = COUNTROWS(Sales)


Examples of Using the COUNTROWS Function

Example 1: Counting the Total Number of Records in a Table

One of the most common use cases of the COUNTROWS function is to count the total number of records in a table. To do so, you simply need to pass the name of the table as an argument to the COUNTROWS function.

The following example demonstrates how to use the COUNTROWS function to count the total number of records in a table named 'Sales':


CountAllSales = COUNTROWS(Sales)


Example 2: Counting the Number of Records That Meet Specific Criteria

Another common use case of the COUNTROWS function is to count the number of records that meet specific criteria. To do so, you need to create a filter context using the FILTER function and then pass the filtered table as an argument to the COUNTROWS function.

The following example demonstrates how to use the COUNTROWS function to count the number of sales made by a specific salesperson:


CountSalesBySalesperson =

COUNTROWS(

FILTER(

Sales,

Sales[Salesperson] = “John Smith”

)

)


Example 3: Calculating the Percentage of Records That Meet Certain Conditions

The COUNTROWS function can also be used to calculate the percentage of records that meet certain conditions. To do so, you need to use the DIVIDE function to divide the number of rows that meet the criteria by the total number of rows in the table.

The following example demonstrates how to use the COUNTROWS function to calculate the percentage of sales made by a specific salesperson:


SalesPercentageBySalesperson =

DIVIDE(

COUNTROWS(

FILTER(

Sales,

Sales[Salesperson] = “John Smith”

)

),

COUNTROWS(Sales)

)


The Power BI DAX function COUNTROWS is a versatile tool that can be used to count the number of rows in a table or a filtered table. In this article, we discussed its syntax and provided examples of its usage in various scenarios. By mastering the COUNTROWS function, you can gain a deeper understanding of your data in Power BI and make more informed business decisions.

Power BI DAX Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

11-13 November 2024

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)