0
0
Power-biHow-ToBeginner ยท 3 min read

How to Use COUNTROWS in DAX in Power BI: Simple Guide

Use the COUNTROWS function in DAX to count the number of rows in a table or a filtered table in Power BI. It takes a single table argument and returns the total count of rows as a number.
๐Ÿ“

Syntax

The COUNTROWS function syntax is simple:

  • COUNTROWS(table)

Here, table is the table or table expression you want to count rows from.

DAX
COUNTROWS(<table>)
๐Ÿ’ป

Example

This example counts the number of rows in the Sales table.

It shows how to create a measure that returns the total number of sales records.

DAX
Total Sales Count = COUNTROWS(Sales)
Output
If the Sales table has 1000 rows, the measure returns 1000
โš ๏ธ

Common Pitfalls

One common mistake is passing a column instead of a table to COUNTROWS. It only accepts tables.

Another is forgetting to use a filter expression inside FILTER() if you want to count rows conditionally.

Example of wrong usage:

COUNTROWS(Sales[OrderID])  -- Incorrect, Sales[OrderID] is a column

Correct usage with filter:

DAX
Count Large Sales = COUNTROWS(FILTER(Sales, Sales[Amount] > 1000))
Output
Returns the count of sales where Amount is greater than 1000
๐Ÿ“Š

Quick Reference

  • COUNTROWS(table): Counts all rows in the table.
  • COUNTROWS(FILTER(table, condition)): Counts rows meeting a condition.
  • Use with calculated tables or filters for dynamic counts.
โœ…

Key Takeaways

COUNTROWS counts the number of rows in a table or filtered table in Power BI.
Always pass a table or table expression to COUNTROWS, not a column.
Use FILTER inside COUNTROWS to count rows based on conditions.
COUNTROWS is useful for creating measures that summarize data counts.
Remember COUNTROWS returns a number representing row count.