Function Problems

How to Count Rows When a Later Column Contains NULL in Excel

Huma Ashraf ChHuma Ashraf Ch Nov 13, 2026 869 views

Question details

The user needs to count 'Shopping' entries in each row only when a later column in that row contains the text 'NULL'; rows without NULL after the target value must not be counted.

How to Count Rows When a Later Column Contains NULL in Excel
Product
WPS Office Spreadsheets
Device & OS
not provided
Scenario
The user has a table or row range with text values and wants a formula to perform a row-wise conditional count based on the order of two values.
Observed behavior
Standard aggregate counting does not consider the left-to-right order of values within each row, so the result must be calculated with dynamic array or lookup formulas.
Before you start

Confirm that the source range has a consistent column order and that the cells contain the exact text "Shopping" and "NULL" with no extra spaces. If the table has hidden columns, decide whether they should be included in the row-wise search.

Solution 1Recommended

Use BYROW with a custom CountBeforeLambda to count qualifying rows

Best for modern Excel and WPS Spreadsheets that support dynamic arrays and LAMBDA. This method calculates each row independently and returns a spilled result.

Define a reusable LAMBDA that accepts a value to count and a stopping value. For each row, it finds the last occurrence of the stopping value, takes only the cells up to that position, and counts how many equal the target value.

Use a named table or a fixed range as the first argument to BYROW. The result is 1 when the target appears before the last stop value; otherwise it is 0.

1
Create the CountBeforeLambda name

Open WPS Spreadsheets, click Formulas > Name Manager > New, enter the name CountBeforeLambda, and paste this formula: =LAMBDA(countString,untilString,LAMBDA(line,LET(end,XMATCH(untilString,line,,-1),matches,TAKE(line,,end)=countString,IFERROR(SUM(SIGN(matches)),0))))

2
Enter the BYROW formula

Select an empty cell outside the table and enter =BYROW(table,CountBeforeLambda("Shopping","NULL")). Replace table with your actual table name or range, then press Enter.

3
Verify the spilled results

Confirm that each row returns 1 when "Shopping" occurs before the last "NULL" and returns 0 when the condition is not met.

Use BYROW with a custom CountBeforeLambda to count qualifying rows
Result: This formula counts qualifying rows by evaluating the row order, so a row with NULL before Shopping is not counted.
WPS Spreadsheets formula help

Count rows with NULL after Shopping directly in WPS Office Spreadsheets

Open your workbook in WPS Office Spreadsheets and use the same Excel-compatible dynamic array functions, BYROW, LAMBDA, and XMATCH, to count row-wise conditions. WPS reads and writes .xlsx files, so you can apply this solution without changing tools or losing format.

  1. 1. Open the workbook in WPS Spreadsheets: Launch WPS Office, click Menu > Open, and select the Excel file that contains the table or row range.
  2. 2. Define the CountBeforeLambda name: Click Formulas > Name Manager > New, name it CountBeforeLambda, and paste the LAMBDA formula shown in the solution above.
  3. 3. Apply the BYROW formula: Click an empty cell and enter =BYROW(table,CountBeforeLambda("Shopping","NULL")), replacing table with the actual table name or range.
  4. 4. Review and save the results: Press Enter, confirm each row shows 1 or 0 as expected, then save the workbook in .xlsx format.
Uses familiar Excel-compatible BYROW, LAMBDA, and XMATCH formulasFull support for .xlsx and other Microsoft Excel formatsFree, lightweight spreadsheet application with a familiar ribbon interfaceNo VBA or macro required for row-wise conditional counting
microsoft office alternative - wps office

Frequently Asked Questions

Does this formula work in every version of Excel or WPS Spreadsheets?

BYROW and LAMBDA require a version that supports dynamic array functions, including Microsoft 365 and recent WPS Office Spreadsheets. In older versions, use the XMATCH row formula if available, or check for updates.

What happens if NULL appears before Shopping in a row?

The row returns 0 because the formula compares the last NULL position with the Shopping position. A NULL located before Shopping does not satisfy the 'later column contains NULL' condition.

Can I use a normal range instead of a named table?

Yes. For BYROW, use a fixed range such as C2:G8 as the first argument. For the shorter method, use the row range formula and fill it down.

Why does my formula return #NAME? in WPS Spreadsheets?

#NAME? usually means the CountBeforeLambda name has not been created, the formula spelling is incorrect, or the installed WPS version does not support LAMBDA. Verify the name in Formulas > Name Manager and update WPS Office if needed.

Can I count a different target value or stopping text?

Yes. Replace "Shopping" and "NULL" in the formula with the target and stopping text you need. The LAMBDA method accepts these as arguments, so no other change is required.