How to check if subsequent non-empty cells contains the same value? - google-sheets

I would like to count if in the column there are N subsequent elements of a certain value (in this example it's 1). So for the below example, it should return true for A, but false for B. Empty cells shall be ignored.
A B
+---+---+
| 1 | 1 |
| 1 | 1 |
| 1 | 1 |
| | |
| 1 | 2 |
| | 1 |
+---+---+
| Y | N | <-- RESULT
+---+---+
Ideally would be if I could mark all of those 4 or more subsequent cells.

Have a look at this one as well - you need to pull it across for columns B, C etc.
=ArrayFormula(max(frequency(if(filter(A:A,A:A<>"")=1,sequence(count(A:A)),""),if(filter(A:A,A:A<>"")<>1,sequence(count(A:A)),"")))>=4)
So how does this work? It goes all the way back to #Barry Houdini, who as far as I know was the first to post this elegant method to find the longest sequence of repeated values within a range in Excel.
It uses Frequency. Frequency counts the number of values which fall within a series of bins defined by cut points
Frequency(<Values>,<Cut points>)
So if your cut points were 10,20,30 and your values were 12,15,25,35,36,37 you would expect the counts to be 2,1 and 3.
#Barry's insight was to realise that if you made the row numbers for values that you didn't want to count be the cut points and the row numbers for values you did want to count (in this case 1) be the values, then you could use Frequency to count up the number of consecutive values of interest. This led him to this formula (in his case looking for consecutive zeroes bounded by ones):
=MAX(FREQUENCY(IF((A2:A100=0)*(A2:A100<>""),ROW(A2:A100)),IF(A2:A100=1,ROW(A2:A100))))
which is easily adapted for the present situation simply by changing 0 to 1 and 1 to <>1, filtering out the blanks and using Sequence instead of row number.

try:
=ARRAYFORMULA(IF(TRANSPOSE(MMULT(TRANSPOSE(N(REGEXMATCH(""&
IF(A1:B6="", 1, A1:B6), "1"))),
SEQUENCE(ROWS(A1:B6), 1)^0))/ROWS(A1:B6)=1, "Y", "N"))

Related

Find query matches for a multi-row input

Basically I have a set of CSV that I want to search through using a key from outside the query area. The query data is arranged like:
| COLUMN L | COLUMN K |
|----------|----------|
| A,B,C,D | 1 |
| E,F,G,H | 2 |
| I,J,K | 3 |
etc
What I have so far is
query(A1:L12,"Select L where K matches '(?:^|,)"&A13&"(?:,.*|$)'",-1)
So if A13's value is G, 2 is returned.
This works fine and returns the correct row value where it matches A13, but what I actually want to do is for this to process a column of data and return results for each key (or A13 value), but I can't work out how to translate this into "arrayformula" format. I tried this:
query(A1:L12,"Select L where K matches '(?:^|,)"&A13:A24&"(?:,.*|$)'",-1)
But no luck.

Multi-level and multi-argument Index in Google Sheets

I am writing a sheet where I am trying to create a multi level Index that searches through 5 different columns with 3 pieces of data. So for example:
x = 40
y = 5000
z = 20000
Column1 | Column2 | Column3 | Column4 | Column5 | Column6
13 | 29 | 0 | 0 | 0 | Yes
30 | 870 | 0 | 0 | 0 | No
10 | 870 | 0 | 30000 | 1 | Blue
10 | 870 | 30001 | 100000 | 1 | Yes
10 | 870 | 100001 | 300000 | 1 | Unknown
Here's a sample set of my data, what I need is to compare
the variable x to columns 1 and then 2 (x must fall between these values)
variable y to columns 3 and 4 (y must fall between these values)
and then finally z to column 5 (z must be above these values)
In each of these cases I need to know if the the variable is either lower than or higher than . Finally, I need the matching data from column 6 to be returned as a result in my sheet. At the moment I have a simply IMMENSE list of nested if statements which consider all of these criteria separately but it doesn't lend itself very well to editing when changes need to be made to the values.
I've looked at every single page on the internet (every... single... page...) and can't seem to find the solution to my issue. Most solutions I have found are either using a single data point, using multiple data points against a single range or simply don't seem to work. The latest iteration I have tried is:
=INDEX('LTV Data'!$N$3:$N$10, MATCH($D$5 & $G$8 & $G$12, ARRAYFORMULA($D$5 <= 'LTV Data'!$H$3:$H$10 & $D$5 >= 'LTV Data'!$I$3:$I$10 & $G$12 <= 'LTV Data'!$J$3:$J$10 & $G$12 >= 'LTV Data'!$K$3:$K$10 & $G$8 <= 'LTV Data'!$L$3:$L$10), 0), 7)
But this only produces an error as the separate values I want to test against are concatenated and the Match can't find that string. I'm also unsure about the greater than and less than symbols as to how valid that syntax is. Is anyone able to shed some light on how I can achieve the result I need in a more elegant way than the mass of IFS, ANDS + ORs I have right now? Like I said, it works but it sure ain't pretty ;)
Thanks a bunch in advance!
ETA: So with the above variables the result I would like would be 'Blue'. This is because x falls between columns 1 and 2, y falls between columns 3 and 4 and z is higher than column 5 on the third row. This is all contained in the MATCH statement in the example code above. Please see the MATCH statement to see the comparisons I am trying to make.
You need to put the different criteria together using multiplication if you want to get the effect of an AND in an array:
=INDEX(F2:F10,MATCH(1,(A2:A10<x)*(B2:B10>x)*(C2:C10<y)*(D2:D10>y)*(E1:E10<z),0))
or
=INDEX(F2:F10,MATCH(1,(A2:A10<=x)*(B2:B10>=x)*(C2:C10<=y)*(D2:D10>=y)*(E1:E10<=z),0))
to include the equality (I have used named ranges for x, y and z).
Works in Google Sheets and (if entered as an array formula) Excel.
In Google Sheets you also have the option of using a filter
=filter(F2:F10,A2:A10<=x,B2:B10>=x,C2:C10<=y,D2:D10>=y,E2:E10<=z)
but then you aren't guaranteed to get just one row.

How to count distinct errors in google sheets/excel (NON-SQL)?

Column A (Error.Type) |
(Or any other text) | Column B (Message)
> 1 | #REF! |
> 1 | #REF! | total for error 1 is 2
> 2 | #DIV/0! |
> 2 | "Hello World" | total for error 2 is 2
> 3 | "Foobar" |
> 3 | "Something" |
> 3 | "Else" | total for error 3 is 3
// the number is based on error.type, there are other columns
grand total i need to return 2 + 2 + 3 = 7
=(countif(k:k,k1)>1)) <- this code will return all under conditional formatting
but =count((countif(k:k,k1)>1))) is a circular dependency and i don't know why?
Circular dependency occurs when a formula includes a reference to the cell that holds it. If cell A1, has =A1 the result is the referred error message
=count((countif(k:k,k1)>1)) will return the circular dependency error if it's included on any cell on the K column, on any other column it should work fine.
It sounds like what you are needing is the COUNTIFS() formula. For example, the following function will return a TRUE value for all the rows except the ones with >1 and #REF! in your example. Thus, giving you your uniques.
=COUNTIFS($A:$A,$A1,$B:$B,$B1)=1
Returning this true value for conditional formatting will make w/e you're needing happen on the Range you have it applied. This is assuming whatever value you need in K isn't really needed.
For distinct counts, you can use a helper column (say somewhere in the far right) like this. It will return 1 for each distinct.
| D |
=COUNTIFS(A$1:A1,A1,B$1:B1,B1)
Then this formula will get the total distincts.
=COUNTIF(D:D,1)

Google Spreadsheet compare range of LEFTs and RIGHTs

I would like to COUNTA on a range of cells in a column where I compare if LEFT number is greater than RIGHT number of the cell's value and if the same relation exists in the other column.
In more simple words, for example I do have two column with the person's A and B result predictions of five matches:
| A | B
1 | 2:0 | 2:0
2 | 0:0 | 1:0
3 | 1:2 | 3:0
4 | 1:0 | 0:1
5 | 1:0 | 2:0
And I would like to check the number of rows where columns A and B point the home team as a winner in the same match.
So the result of the function in this case should be 2 as A and B have pointed home team in 2 matches (match 1 and 5).
Thank you in adnavce!
Using the E/F column references in your comment:
=COUNTA(IFERROR(FILTER(E2:E100;LEFT(E2:E100)>RIGHT(E2:E100),LEFT(F2:F100)>RIGHT(F2:F100))))
Note (1): will fail if >=10 goals are predicted (there would be a workaround though).
Note (2): without the IFERROR, when a result of 0 is expected, 1 will be returned.

SUM cells until current cell where value of another column is the same

I need to SUM all values in the column till the current cell, where the values in a different column are the same.
Example:
------------------------------------------------------
| FIRST | SECOND | SUM |
------------------------------------------------------
| VALUE A | NUMBER 1 | NUMBER 1 |
------------------------------------------------------
| VALUE A | NUMBER 2 | NUMBER 1 + NUMBER 2 |
------------------------------------------------------
| VALUE B | NUMBER 3 | NUMBER 3 |
-------------------------------------------------------
| VALUE B | NUMBER 4 | NUMBER 3 + NUMBER 4 |
-------------------------------------------------------
| VALUE B | NUMBER 5 | NUMBER 3 + NUMBER 4 + NUMBER 5 |
-------------------------------------------------------
The first column has strings, the second numbers and the first holds the results.
Write an if statement to do this. Compare the value of the first column between the current and previous rows, if they have the same value add previous sum and current value together, otherwise the sum becomes the current value.
In code, this would be the formula in C3
=if(exact(A3,A2),C2+B3,B3)

Resources