Place a Value Beside the First Nonzero Entry in Each Excel Group
Question details
Place a value beside only the first row with a nonzero related value for every distinct group listed in Column A.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Groups appear across different row ranges in Column A, while the values to evaluate are stored in Column B.
- Observed behavior
- The desired output must identify the first nonzero value within each group and leave later nonzero entries for that same group blank.
Confirm that each group has a consistent value in Column A and that the data begins on row 2. Decide whether the result should display the first nonzero value from Column B or a fixed label, such as "First".
Use COUNTIFS to return the first nonzero value for each group
Use this formula when you want the result column to show the Column B value only on the first nonzero row for each group in Column A.
The formula counts prior nonzero entries for the current group. When the count is 1, the current row is the first nonzero entry in that group.
For example, if group names are in A2:A100 and related values are in B2:B100, enter the formula in C2 and fill it down.
Insert or select an empty result column, such as Column C, and click cell C2.
Type =IF(AND(B2<>0,COUNTIFS($A$2:A2,A2,$B$2:B2,"<>0")=1),B2,"") and press Enter.
Select C2, then drag the fill handle down or double-click the fill handle to apply the formula to the remaining rows.
To show a marker instead of the value from Column B, replace the second B2 in the formula with a text value, such as "First": =IF(AND(B2<>0,COUNTIFS($A$2:A2,A2,$B$2:B2,"<>0")=1),"First","").

Use COUNTIF when every group needs only its first occurrence marked
Use this shorter method when the first row of the group should be marked regardless of whether the related value in Column B is zero.
Mark the First Nonzero Value in Each Group with WPS Spreadsheets
WPS Spreadsheets supports COUNTIFS formulas for identifying the first nonzero value within each group. Enter the formula in a result column, fill it down, and review the one marked value per group in the same worksheet.
- 1. Open the worksheet in WPS Spreadsheets: Open the Excel workbook in WPS Office and verify that group names are in Column A and values are in Column B.
- 2. Choose the output column: Click the first empty result cell, such as C2, beside the first data row.
- 3. Insert the COUNTIFS formula: Enter =IF(AND(B2<>0,COUNTIFS($A$2:A2,A2,$B$2:B2,"<>0")=1),B2,"") and press Enter.
- 4. Apply the formula to all rows: Drag or double-click the fill handle on C2 to copy the formula through the data range.

Frequently Asked Questions
What does the COUNTIFS formula return for later nonzero rows in the same group?
It returns a blank because COUNTIFS finds more than one nonzero entry for that group by the time it reaches a later row.
How can I display a fixed word instead of the first nonzero value?
Replace the returned B2 reference with text in quotation marks. For example: =IF(AND(B2<>0,COUNTIFS($A$2:A2,A2,$B$2:B2,"<>0")=1),"First","").
Does the formula work when the same group appears again after other groups?
Yes. Because the formula counts all rows from row 2 through the current row, it treats every occurrence of the same value in Column A as part of one group.
Why is the formula marking a blank cell as a nonzero value?
Check that Column B contains actual numeric values and not text values, spaces, or formulas returning unexpected text. Convert text numbers to numbers before applying the formula.
Can I use this formula in WPS Spreadsheets?
Yes. WPS Spreadsheets supports IF, AND, COUNTIF, and COUNTIFS formulas and can open Excel .xlsx and .xls workbooks.




