Pinterest Pixel

COUNTROWS in Excel Power Pivot

Bryan
Power Pivot in Excel is a game-changer when it comes to handling large datasets and creating advanced calculations.
One of the powerful features of Power Pivot is Measures (called Calculated Fields in Excel 2013).

Measures allow you to create dynamic formulas that interact with Pivot Tables, making your analysis more flexible and insightful.

Among these, the COUNTROWS function stands out as a simple yet impactful tool that helps you count the number of rows in a table.

Power Pivot in Excel is a game-changer when it comes to handling large datasets and creating advanced calculations. One of the powerful features of Power Pivot is Measures (called Calculated Fields in Excel 2013). Measures allow you to create dynamic formulas that interact with Pivot Tables, making your analysis more flexible and insightful. Among these, the COUNTROWS function stands out as a simple yet impactful tool that helps you count the number of rows in a table.

In this article, we will take a deep dive into COUNTROWS in Excel Power Pivot. We’ll explain what it is, why it’s useful, and provide a step-by-step example. To keep things structured, the article is divided into main topics with sub-topics under each.

Key Takeaways:

  • COUNTROWS is a DAX function in Power Pivot that counts rows in a table.
  • Measures make Pivot Table analysis dynamic and scalable.
  • Creating a COUNTROWS measure is simple with the Data Model setup.
  • COUNTROWS can be combined with filters for advanced insights.
  • Practical applications include sales, HR, inventory, and project tracking.

COUNTROWS in Excel Power Pivot | MyExcelOnline

download excel workbook Countrows.xlsx

 

Introduction to Measures in Power Pivot

What Are Measures?

Measures are formulas you create in Power Pivot to perform calculations on your data model. Unlike normal Excel formulas, measures are evaluated in the context of Pivot Tables. This means they automatically adjust depending on filters, rows, and columns applied in the report. For example, a SUM measure can total sales figures by product, region, or month, depending on the structure of your Pivot Table.

Why Use COUNTROWS?

COUNTROWS is particularly useful when you want to count the number of entries in a table. This can be handy for tasks like counting the number of sales transactions, the number of customers, or even the number of orders processed. Unlike Excel’s simple COUNT formula, COUNTROWS works on tables inside the Power Pivot Data Model, ensuring scalability for large datasets.

 

Preparing the Data Model

Creating a Table

STEP 1: Select the Sales Table. Go to Insert > Table.  Click OK.

COUNTROWS in Excel Power Pivot

STEP 2: Go to Table Tools > Design > Table Name  and give your new Table a descriptive name.  In our example, we will name it Sales

COUNTROWS in Excel Power Pivot

Adding the Table to the Data Model

In Excel 2013 & 2016

Select your Sales Table. Go to Power Pivot > Add to Data Model.

This will import your new Table into the Power Pivot Window.

COUNTROWS in Excel Power Pivot

In Excel 2010

Go to PowerPivot > Create Linked Table.

Linking Excel Tables in Power Pivot

This will open the Power Pivot Window.

The Sales Table will now be automatically loaded to the Power Pivot Data Model.

COUNTROWS in Excel Power Pivot

Now, Close the Power Pivot Window. 

Using Measures in Power Pivot

COUNTROWS in Excel Pivot Table

STEP 1: Go to Insert> Pivot Table.

Using Measures in Power Pivot

In Excel 2016

Select Use this workbook’s Data Model.  This will use the Data Model you just uploaded in the last step.

Select the Existing Worksheet and choose your location for your Pivot Table and press OK.

COUNTROWS in Excel Power Pivot

In Excel 2013

Go to Use External Data Source > Choose a Connection

Using Measures in Power Pivot

Now select Tables > This Workbooks Data Model > Open:

Using Measures in Power Pivot

In Excel 2010

Go to Use an External Data Source > Choose Connection:

Using Measures in Power Pivot

Now select PowerPivot Data > Open:

Using Measures in Power Pivot

STEP 2: Adding a Measure:

In Excel 2016

On the Sales Table, right-click and select Add Measure.

COUNTROWS in Excel Power Pivot

An alternative way in Excel 2016 is go to Power Pivot > Measures > New Measure.

Using Measures in Power Pivot

In Excel 2013

Go to PowerPivot > Calculated Fields > New Calculated Field

(In Excel 2013 “Measures” were renamed “Calculated Fields” and returned to “Measures” in Excel 2016…I know, how annoying!)

Using Measures in Power Pivot

In Excel 2010

On the Sales table, right-click and select Add New Measure.

Using Measures in Power Pivot

An alternative way in Excel 2010 is to select a cell inside the Pivot Table that was created in the previous step and go to Power Pivot > New Measure:

Using Measures in Power Pivot

STEP 3: This is where we create our Measure using the COUNTROWS function.

For Measure Name, type in any name that you like e.g. Number of Sales

For the Formula, after the = sign start typing the word COUNTROWS.

Just like in native Excel, this will bring up the Formula helper and choose the COUNTROWS function by either double clicking on the blue highlighted COUNTROWS option or by pressing the Tab keyboard to confirm this suggestion:

COUNTROWS in Excel Power Pivot

After the COUNTROWS formula is selected, type in the Table name that we created in Step 2, which we called Sales.

This will bring up the Formula helper and within here you need to select the Sales Table option and close the parentheses:

COUNTROWS in Excel Power Pivot

Set the Category as General, and this will automatically handle the formatting for you.  Press OK to confirm this.

This Measure will now return the Total Number of Rows based on the Pivot Table we will be setting up in the next step.

COUNTROWS in Excel Power Pivot

STEP 4: Place your new Measure Number of Sales in the Values area.

Then place Month in the Rows area

COUNTROWS in Excel Power Pivot

STEP 4: Now we are able to use our new COUNTROW Measure in the Pivot Table.

COUNTROWS in Excel Power Pivot

 

Practical Applications of COUNTROWS

  • Sales Analysis: COUNTROWS helps businesses understand the volume of transactions, not just the total revenue. For example, you can see whether sales growth is due to more customers or higher-value purchases.
  • Data Quality Checks: If you expect a certain number of entries (e.g., daily logs, monthly invoices), COUNTROWS can be used to verify completeness of data. Missing rows can be easily detected.
  • Customer Analysis: COUNTROWS can be applied to customer datasets to quickly count how many customers made purchases during a specific period. This helps track customer activity and loyalty.
  • Inventory Management: By applying COUNTROWS to inventory movement logs, businesses can count stock transactions, which helps identify fast-moving or stagnant items.
  • Employee or HR Tracking: In HR datasets, COUNTROWS can help track the number of employees by department, joiners per month, or attrition-related entries.
  • Project Management: For project data, COUNTROWS can help count the number of tasks completed, milestones achieved, or issues logged, making tracking easier.

 

FAQs

Q1. What is COUNTROWS in Power Pivot?

COUNTROWS is a DAX function that counts the number of rows in a specified table within the Data Model. It works differently from Excel’s COUNT function because it operates on Power Pivot tables. This makes it more scalable for large datasets. It can be used directly in a Measure to provide insights within Pivot Tables. Essentially, it’s a fast way to get transaction or record counts dynamically.

Q2. How do I create a COUNTROWS measure in Excel?

First, add your dataset to the Power Pivot Data Model. Then, insert a Pivot Table that uses the Data Model. From there, add a new Measure and type =COUNTROWS(TableName). Assign a name like “Number of Sales” and set the format as General. Finally, place the Measure in the Pivot Table Values area for analysis.

Q3. How is COUNTROWS different from COUNT in Excel?

The COUNT function in Excel only counts cells with numeric values, and it works on raw worksheet data. COUNTROWS, however, works at the Data Model level and counts all rows regardless of cell values. This makes it ideal for transaction-based or log-based datasets. It scales better when handling thousands or millions of rows. Plus, it integrates seamlessly with other DAX functions like CALCULATE or FILTER.

Q4. Can COUNTROWS be used with filters?

Yes, COUNTROWS can be combined with filters to create more specific insights. For example, you can count only rows where sales occurred in a particular region or month. This is done using the FILTER function within DAX. It allows you to create conditional row counts without writing multiple separate formulas. This makes your analysis flexible and highly targeted.

Q5. What are some practical uses of COUNTROWS in business?

COUNTROWS is widely used for transaction volume analysis in sales. It helps verify data completeness in logs and reports. In HR, it can track employee counts or attrition trends. In inventory, it helps count stock movement transactions. For projects, it monitors the number of completed tasks or milestones for progress tracking.

PIVOT BANNER

If you like this Excel tip, please share it



COUNTROWS in Excel Power Pivot | MyExcelOnline


Bryan

Bryan Hong is an IT Software Developer for more than 10 years and has the following certifications: Microsoft Certified Professional Developer (MCPD): Web Developer, Microsoft Certified Technology Specialist (MCTS): Windows Applications, Microsoft Certified Systems Engineer (MCSE) and Microsoft Certified Systems Administrator (MCSA).

He is also an Amazon #1 bestselling author of 4 Microsoft Excel books and a teacher of Microsoft Excel & Office at the MyExecelOnline Academy Online Course.

See also  Advanced Editor In Power Query

Star 30 Days - Full Access Star

One Dollar Trial

$1 Trial for 30 days!

Access for $1

Cancel Anytime

One Dollar Trial
  • Get FULL ACCESS to all our Excel & Office courses, bonuses, and support for just USD $1 today! Enjoy 30 days of learning and expert help.
  • You can CANCEL ANYTIME — no strings attached! Even if it’s on day 29, you won’t be charged again.
  • You'll get to keep all our downloadable Excel E-Books, Workbooks, Templates, and Cheat Sheets - yours to enjoy FOREVER!
  • Practice Workbooks
  • Certificates of Completion
  • 5 Amazing Bonuses
Satisfaction Guaranteed
Accepted paymend methods
Secure checkout

Get Video Training

Advance your Microsoft Excel & Office Skills with the MyExcelOnline Academy!

Dramatically Reduce Repetition, Stress, and Overtime!
Exponentially Increase Your Chances of a Promotion, Pay Raise or New Job!

Learn in as little as 5 minutes a day or on your schedule.

Learn More!

Share to...