How to Subtract the Count of Specific Text from a Number in Excel
Question details
The user needs a formula to count occurrences of specific text strings ('PM' and 'N') in a given range, multiply that count by 8, and subtract the final product from a starting value like 70.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Calculating a remaining balance, score, or hours based on the occurrences of specific status codes (e.g., 'PM' or 'N') in a dataset.
- Observed behavior
- Requires an efficient combined formula using COUNTIF and arithmetic operations instead of calculating the counts and subtractions manually.
Ensure your data range does not contain leading or trailing spaces around the target text strings, as this can cause the COUNTIF function to miss matching cells.
Use COUNTIF with an Array Constant
Use a single formula combining SUM, COUNTIF, and an array constant to efficiently count multiple text criteria and perform the subtraction at once.
This method is the most efficient because it combines multiple criteria into a single array constant. The COUNTIF function will output an array of counts for both 'PM' and 'N', which the SUM function then adds together before multiplying and subtracting.
Click on the cell where you want the final calculated result to appear.
Begin your formula by typing the cell reference that contains your starting value (for example, A1 for the number 70) followed by a minus sign: =A1-
Complete the formula by entering SUM(COUNTIF(B1:N1,{"PM","N"}))*8, replacing B1:N1 with your actual data range.
Press Enter. The full formula should look like =A1-SUM(COUNTIF(B1:N1,{"PM","N"}))*8. Excel will automatically calculate the result.
Use Chained COUNTIF Functions
If you prefer avoiding array constants or need to apply different multipliers for each text string, you can chain multiple COUNTIF functions together.
Easily Calculate Advanced Formulas with WPS Office
WPS Spreadsheet offers full support for advanced array formulas, SUM, and COUNTIF functions, making it simple to perform complex data calculations and conditional counting without errors.
- 1. Open your workbook: Launch WPS Spreadsheet and open the file containing your text data and starting values.
- 2. Enter your formula: Click on the target cell and type your combined SUM and COUNTIF formula.
- 3. Utilize the Formulas tab: Use the 'Formulas' tab on the top ribbon to access function hints, syntax guides, and error-checking tools.
- 4. Calculate instantly: Press Enter to instantly calculate your conditional subtractions with precision.

Frequently Asked Questions
Why is my COUNTIF formula returning a 0 instead of the actual count?
This usually happens if the text in your cells has hidden spaces (like 'PM ' instead of 'PM') or if automatic calculation is turned off. Use the TRIM function to clean your data or check your calculation options in the Formulas tab.
Can I use cell references instead of typing 'PM' and 'N' inside the formula?
Yes. Instead of the array {"PM","N"}, you can reference cells containing your criteria. For example, =A1-(COUNTIF(B1:N1, X1)+COUNTIF(B1:N1, Y1))*8 where X1 and Y1 contain your targeted text strings.
Does this formula work in both Excel and WPS Spreadsheet?
Absolutely. Both Microsoft Excel and WPS Spreadsheet fully support the SUM and COUNTIF combination with array constants, ensuring seamless compatibility for your calculation workbooks.
How do I change the formula to count a third text string?
You can easily expand the array constant. To count 'PM', 'N', and 'AM', update the formula to =A1-SUM(COUNTIF(B1:N1,{"PM","N","AM"}))*8.




