简体   繁体   中英

Use only one formula in Excel to count results of multiple COUNTIF

Hello you all Excel gurus,

I have an Excel spreadsheet that contains an undefined number of lines (from 1 to x - x being generally less than 200). Each line has a few initial columns with some data (item number, dates, ...) and, starting at column I, an undefined number of columns (from 1 to x - x being generally less than 50) than can be either empty or contain an "x".

In each line I would like to count the number of "x" (this I know how to do with the COUNTIF function). In a different sheet, I would like to count the number of times the count is 1, the number of times the count is 2, and so on until 6.

Problem for me is that the number of lines and columns being changing, I wanted to put all this in a single formula, using arrays but all my tries failed.

My current formula to get the number of lines totaling 1 is:

{=SUM(IF(SUM(IF(OFFSET(OFFSET($H$2;1;0;TotalLines;1);0;1;1;TotalColumns)="x";1;0))=1;1;0))}

With TotalLines and TotalColumns being named ranges containing the result of lines count and column count respectively, so that I have the exact number of lines and columns currently displayed.

Obviously the formula does not work...

Could you please advise on how to proceed,

Thank you in advance for your support

I would say the easiest approach here is to just add in a helper column on the first sheet, where each row has its own COUNTIF function checking the number of "x"s. For clarity to others who may read this (as you are familiar with COUNTIF), I would suggest the following [Put in, say, column D, or whichever column comes immediately after your otherwise-final "data" column", starting in row 2 and dragged down]:

=COUNTIF(OFFSET($D$1,ROW(),1,1,TOTALCOLUMNS),"x")

Then in your other tab simply perform a COUNTIF over your individual checks in column D, like so [starting on row 2, assuming that your main data is in Sheet1, and that on Sheet2 column A, you have the number of "x"s you're checking for {1, 2, etc.}]:

=COUNTIF(Sheet1!D:D,A2)

It looks like you can pivot the first column on countif of yours. Just pick this column and insert a pivot table. Take the same variable to rows and to values as count. If your base table is changed, just refresh it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM