Google Sheets CountIFS - google-sheets

I have a Google spreadsheet that I am trying to count scores of 1 to 5. I can do a COUNTIF to count the number of 5s, 4s, 3s, etc.
I need to count the the values separately depending if the value of the first row begins with a space or not. The COUNTIFS formula will not work, since the arrays are the same size.
My formulas are:
With space:
=COUNTIFS(B1:F1,=" *",B2:F5,"=5")
Without space:
=COUNTIFS(B1:F1,="<> ",B2:F5,"=5")
Here is a sample of my spreadsheet: https://docs.google.com/spreadsheets/d/1xmEpTgBKDh-ZuLuxijbqAwx4nRKrThv5LnTI5TgP5XI/edit?usp=sharing
I have several forms and the number of cells that begin with a space varies per sheet and I rather create a formula that works for all of them.
Is there another option I can use other than COUNTIFS?

Try something like
=countif(filter(B2:F5, regexmatch(B1:F1, "^\s")), "=4")
and see if that works?
And for the header rows that do not start with a space
=countif(filter(B2:F5, left(B1:F1, 1)<>" "), "=3")

Related

Google Sheets: how to sum a dynamic range across columns using a variable to determine range length

I'm trying to write a formula in Google Sheets that will enable me to sum a range of values across columns, where I can manipulate the number of cells to be summed across the column with a variable. For example:
if my variable is 5, then I want to sum(D3:H3);
and if my variable is 9, then I want to sum(D3:L3)
Furthermore, I want a formula that I can drag across columns so that the range it's summing moves relative to the cell the formula is in. In the example above with the variable=5:
the formula in cell A3 would be sum(D3:H3);
and the formula in cell B3 would be sum(E3:I3)
etc.
I created a sample spreadsheet here for more context.
Thanks for reading!
I've added a sheet ("Erik Help"). See formula in B5:P5.
Here is the B5 formula (which was then dragged across to P5):
=ArrayFormula(SUM(FILTER($B$1:$1,COLUMN($B$1:$1)>(COLUMN()-$B$4),COLUMN($B$1:$1)<=COLUMN())))
There may be an array approach. But since you have such limited data, this is just as effective with less time investment required to develop the solution.
In plain English, the formula reads "Sum the numbers from B1:1 where the column is greater than X rows back and no greater than the current column" (where X is the value set in B4).
paste in column B and drag to the right:
=IF(COLUMN()-1<$B1, "-", SUM(INDIRECT(
ADDRESS(3, COLUMN()-($B1-1))&":"&
ADDRESS(3, COLUMN()))))

Get count of cells in column where sum of those cells are less than a specified value

I have a spreadsheet where I am trying to get the count of cells in a column, where their sumproduct value reaches a specified number (I wrote comments on the spreadsheet that should make it clearer).
So far I have got some sort of formula, but it is returning me the total count of all cells in the range a specify? I cannot figure out how to do this, so any help would be much appreciated.
My formula:
=ArrayFormula(countif(sumif(SUMPRODUCT(AB13:AB,if($X$13:$X<>"",1/$X$13:$X,1)),"<="&AB13:AB167,AB13:AB167),"<="&abs(AB9)))
Here's my copy of your sheet. It's set to "anyone can edit".
https://docs.google.com/spreadsheets/d/1ebu7UNCVuG7DyC4kVGLiRr3AT4vyU2V_lwlnALQfGy4/edit?usp=sharing
This is the formula I came up with. It gets rid of the need for the row count column you have.
=ARRAYFORMULA(MATCH(F11,MMULT(N(ROW(F13:F)>=TRANSPOSE(ROW(F13:F))),IFERROR(F13:F/MMULT(N($F13:$H<>""),TRANSPOSE(COLUMN($F13:$H)^0)),0))))
It will be a little slow with very large sheets. You'd need a different solution if you were going to have more than a couple thousand rows.

Count number of times values increase in range - Google Sheets

how are you? I'm just not sure what to do here, but I surely can use your help!
I have a series of values in a row range, such as in the following:
1000 2000 1500 2100 3200
I need to figure out a google sheets formula to put in the 6th cell of this row that counts the number of times the value of any cell is greater than the one to the left of it. In this example, my result should be 3.
Is there any way that this can be done? In Excel or Google Sheets, either is great to learn.
Thank you
You can also try the following formula
=COUNTIF(QUERY({{"";TRANSPOSE(B2:F2)},{TRANSPOSE(B2:F2);""}},
"select Col1-Col2 offset 1 label Col1-Col2 ''",0), "<0")
Assuming you have data in A2:E, place the following in F2:
=ArrayFormula(IF(A2:A="",,MMULT(IF(B2:E>A2:D,1,0),SEQUENCE(4,1,1,0))))
Since there are only four columns that might be greater than others (B:E), you can structure it this way. MMULT is hard to explain, but it essentially multiplies everything in each row of one matrix (range) by everything in another range and then adds them. SEQUENCE just forms a column of four 1's by which to multiply then add together everything in each row of the first range. Since anything times 1 is the original number, this just serves to to row-by-row addition.
This formula will process as many rows as have data in A2:E.
try in 7th column on row 2:
=ARRAYFORMULA(MMULT(IF(A2:E4<B2:F4, 1, 0), {1;1;1;1;1}^0))

Counting the Number of Empty Cells between Non-Empty Cells in Google Sheets

I'm trying to count the number of empty cells that exist in a column between each non-empty cell but haven't been able to work out how.
Using this, I'm also trying to find the largest "empty distances" and locate the cell in the center of these distances.
The sheet I'm working with lists a set of marker colors and denotes the ones that are owned out of the full set of colors. I'm trying to find the largest ranges of missing colors and then find the colors in the middle of those ranges in order to find a handful of markers that would best help to fill out the spectrum.
Columns 1-6 are information- Column 7 marks whether the color is owned:
I may have an answer that helps you.
I could only get it to work using a helper column, but someone may know how to eliminate that requirement.
The helper column creates an array, basically listing the row numbers of the rows that have an "x" in your column B.
The main formula then measures the gap between each of these listed row numbers. It also checks the gap before the first "x", and after the last "x". Note that I have the data starting on row 2, which complicates the formula, but makes the sample sheet clearer - this can easily be changed to row 1 if you prefer.
={F2-1;
query(ArrayFormula(if(isnumber(F3:F),F3:F-F2:F-1,"")),
"select Col1 where Col1 > 0",0);
counta(A2:A)-indirect("F"&COUNTA(F$2:F))}
See a sample sheet here:
https://docs.google.com/spreadsheets/d/19QUFGRqTT6BqOsBrEBpTIxQCeNdRa5mzXhxQpCZ8sV4/edit?usp=sharing
Then I used a second formula to calculate the max gap between "x"s, (or before the first or after the last x).
Note that calculating the midpoint of the gaps, and doing a lookup of the corresponding mid-point colour, is something that can be added to this answer, if you share a sample copy of your sheet and share it for editing.
Let me know if this helps. I'll add more explanation to describe what the formula is doing tomorrow.
And I'll provide a second tab with the formulas adjusted to work with data beginning on row 1.
You can also get the lengths of the gaps using Frequency:
=ArrayFormula(frequency(if((B1:B20<>"X")*(A1:A20<>""),row(B1:B20)),if((B1:B20="X")*(A1:A20<>""),row(B1:B20))))
but finding the centres of the gaps and allowing for equal-sized gaps is more difficult.
This should find the position of the "X" at the end of the longest gap:
=ArrayFormula(
sum(frequency(if((B1:B20<>"X")*(A1:A20<>""),row(B1:B20)),
if((B1:B20="X")*(A1:A20<>""),row(B1:B20)))*(sequence(countif(B1:B20,"X")+1,1)<=
match(max(frequency(if((B1:B20<>"X")*(A1:A20<>""),row(B1:B20)),
if((B1:B20="X")*(A1:A20<>""),row(B1:B20)))),frequency(if((B1:B20<>"X")*(A1:A20<>""),row(B1:B20)),
if((B1:B20="X")*(A1:A20<>""),row(B1:B20))),0)))+
countif(sequence(countif(B1:B20,"X")+1,1),"<="&
match(max(frequency(if((B1:B20<>"X")*(A1:A20<>""),row(B1:B20)),
if((B1:B20="X")*(A1:A20<>""),row(B1:B20)))),frequency(if((B1:B20<>"X")*(A1:A20<>""),row(B1:B20)),
if((B1:B20="X")*(A1:A20<>""),row(B1:B20))),0))
)
and then it should just be a case of working backwards from there to the centre of the longest gap. However the formula needs further refinement to deal with the cases
(1) Where the longest gap is after the last "X"
(2) Where there is a tie for the longest gap
(3) Where there is a need to list the longest, second longest, third longest gap etc.

Use ARRAYFORMULA with horizontal COUNTIF

I am using COUNTIF to count the number of occurrences of a value in a horizontal range, which is working fine:
Now I would like to use ARRAYFORMULA to automatically apply that logic to an entire column. My problem is that ARRAYFORMULA doesn't seem to work well with COUNTIF as my range spans both horizontally and vertically. I tried several things:
=ARRAYFORMULA(IF(COUNTIF(B2:D,"Passed")=3,"Passed","Failed")) : the formula doesn't even replicate across the column
=ARRAYFORMULA(IF(ISBLANK(B2:B),"",IF(COUNTIF(B2:D,"Passed")=3,"Passed","Failed"))) : using the extra IF(ISBLANK(B2:B) trick solves the above issue, but the results are wrong
How can I apply ARRAYFORMULA to a formula containing a horizontal COUNTIF?
Here is a link to the spreadsheet if you want to play around
An alternative:
=if(arrayformula(len(B2:B)*(B2:B="P")*(C2:C="P")*(D2:D="P")),"Passed","Failed")

Resources