Function Problems

How to Use COUNTIFS and IFS to Classify and Count Data in Excel

Olivia MillerOlivia Miller Nov 2, 2026 870 views

Question details

The user needs to classify rows in large Excel datasets into categories like MD, NMD, or WIP, and count specific values for each group without displaying repeated results on subsequent rows.

How to Use COUNTIFS and IFS to Classify and Count Data in Excel
Product
Excel
Device & OS
not provided
Scenario
Analyzing and categorizing large datasets where rows need to be classified into specific statuses, counted by group, and formatted cleanly to suppress duplicate values.
Observed behavior
The user requires an efficient formula combination to assign categories, count occurrences using COUNTIFS, and suppress repeated group counts to display only on the first row of each group.
Before you start

Ensure your dataset is sorted by the column you are grouping by, so the formula can correctly identify the start of a new group and suppress repeated values.

Solution 1Recommended

Combine COUNTIFS and IF to Count and Suppress Duplicates

Use a combination of COUNTIFS for conditional counting and an IF statement to ensure the count is only displayed on the first row of each grouped item.

When dealing with grouped data, standard COUNTIFS formulas will return the total count on every row of the group. By multiplying the COUNTIFS result by an IF statement that checks for changes in the group identifier, you can suppress redundant values.

Wrapping the entire formula in an IFERROR function ensures that suppressed rows appear cleanly as blank cells rather than displaying error codes.

1
Set up your classification with IFS

First, assign statuses like MD, NMD, or WIP using an IFS formula. Click on an empty cell and enter your conditions, for example: =IFS(C2="Condition1","MD", C2="Condition2","NMD", TRUE,"WIP").

2
Write the base COUNTIFS formula

To count the specific values (e.g., "NMD") within your group, use COUNTIFS. Enter: COUNTIFS(A$2:A$50000, A2, B$2:B$50000, "NMD"). Ensure you use absolute references (the $ sign) for your data ranges.

3
Add the duplicate suppression logic

Create an IF statement that checks if the current row's group identifier matches the previous row's identifier. Use IF(A2<>A1, 1, "") so it only calculates on the first row of a new group.

4
Combine into a final formula

Merge the steps together inside an IFERROR function to hide errors. Enter the full formula: =IFERROR(COUNTIFS(A$2:A$50000,A1,B$2:B$50000,"NMD")*IF(A2<>A1,1,""),"") in your target cell, press Enter, and drag the fill handle down to apply it to the column.

Combine COUNTIFS and IF to Count and Suppress Duplicates
Performance Tip: Using entire column references (like A:A) in COUNTIFS can slow down large datasets. It is highly recommended to specify the exact data range (like A$2:A$50000) for better calculation performance.
Advanced Data Analysis

Analyze Large Datasets Effortlessly with WPS Spreadsheet

WPS Spreadsheet fully supports advanced array formulas and logical functions like COUNTIFS, IFS, and IFERROR. You can handle massive datasets efficiently without experiencing performance lag.

  1. 1. Open your file in WPS Spreadsheet: Launch WPS Office and open your large dataset.
  2. 2. Select the target cell: Click on the cell where you want to output the grouped count.
  3. 3. Apply the COUNTIFS logic: Paste your combined formula, such as =IFERROR(COUNTIFS(A$2:A$50000,A1,B$2:B$50000,"NMD")*IF(A2<>A1,1,""),"").
  4. 4. Fill the column: Press Enter, then double-click the small square at the bottom-right corner of the cell to automatically fill the formula down the entire dataset.
Fully compatible with Microsoft Excel formulas, including COUNTIFS and IFS.Optimized performance to handle large datasets seamlessly without freezing.Clean, intuitive user interface that requires no learning curve.Free to use with advanced data analysis tools and conditional formatting.
microsoft office alternative - wps office

Frequently Asked Questions

Why is my COUNTIFS formula returning duplicate counts for every row in a group?

By default, COUNTIFS evaluates conditions independently for every row. To show the count only once per group, you need to use an IF statement like IF(A2<>A1, 1, "") to check if the current row belongs to a new group, which prevents the result from repeating.

Can I use the IFS function in older spreadsheet versions?

The IFS function is available in newer spreadsheet software like WPS Office and recent versions of Excel. If you are using an older version, you must use nested IF statements instead (e.g., =IF(Condition1, "Result1", IF(Condition2, "Result2", ...))).

How does the IFERROR function help in this data classification?

When suppressing duplicates by multiplying text or empty strings in a formula, you may encounter #VALUE! errors on non-qualifying rows. Wrapping your formula in IFERROR ensures these rows appear cleanly as blank cells, keeping your dataset tidy.

Do I need dynamic arrays to solve this grouping issue?

While dynamic arrays (like UNIQUE and FILTER) offer an elegant way to handle grouped calculations, you can perfectly achieve the required result using traditional combinations of COUNTIFS and IF logic, which are more backward-compatible across different spreadsheet programs.