Google Sheets IF Statement with Numbers and Text - google-sheets

I'm looking through cells L5 through L9, and if the sum of those cells is equal to 0 AND one (or more) of the cells contains the letter T, then put the letter T into cell L10. If either one of those conditions aren't met, then put the sum of those cells instead. This is what I'm trying:
=IF((AND(SUM(L5:L9)=0.00, REGEXMATCH(L5:L9,"T")), "T", SUM(L5:L9)))
but I'm coming up with ERROR! Any idea what I'm doing wrong here?

REGEXMATCH is for s single string, not array
Try to join the array of string with JOIN
Also, there is problem in your are brackets.
=IF(AND(SUM(L5:L9)=0.00, REGEXMATCH(JOIN(,L5:L9),"T")), "T", SUM(L5:L9))

try:
=INDEX(IF((SUM(L5:L9)=0.00)*(SUM(REGEXMATCH(L5:L9; "T"))>0); "T"; SUM(L5:L9)))

Related

USING TEXTJOIN AND UNIQUE OVER NON-CONTINUOUS CELLS

OK, relatively simple, but frustrating for me. I think my issue isn't with the TEXTJOIN, but in defining a non-continuous series of cells for the UNIQUE function.
In cell A1, I am using this formula:
=TEXTJOIN("
",UNIQUE(B1,E1,H1,K1,N1))
NOTE: I am trying to do this for a row, and not the entire column that the data is in.
My thought was that it would join only unique values from that series, separated by a hard return.
However, I get an error.
Image of a Google Sheet error with my formula
So, looking for a way to look at a non-continuous series of cells in a row, pull out only unique values, and TEXTJOIN them together with a hard return (new line).
Your formula should be
=textjoin(" ",true,unique({B1;E1;H1;K1;N1}))
encapsulate the cells by {}
try:
=JOIN(" "; UNIQUE({B1;E1;H1;K1;N1})
or:
=QUERY(UNIQUE({B1;E1;H1;K1;N1}),,9^9)

JOIN header row values across a row based on non-blank values in cells

So I have two rows:
ID
TagDog
TagCat
TagChair
TagArm
Grouped Tags (need help with this)
1
TRUE
TRUE
TagDog,TagArm
Row 1 consists mainly of Tags, while rows 2+ are entries. This data ties ENTRIES to TAGS.
What I'm needing to do is concatenate/join the tag names per entry. For example, look at the last column above.
I suspect we could write a formula that would:
Create an array of non-empty cells in the row. (IE: [2,4])
Return it with the header row A (IE: [A2,A4])
Then join them together by a comma
But I am unsure how to write the formula, or if this is even the best approach.
Here's the formula:
={
"Grouped Tags (need help with this)";
ARRAYFORMULA(
REGEXREPLACE(TRIM(
TRANSPOSE(QUERY(TRANSPOSE(
IF(NOT(B2:E11),, B1:E1)
),, COLUMNS(B1:E1)))
), "\s+", ",")
)
}
The trick used is called vertical query smash. That's the part:
TRANSPOSE(QUERY(TRANSPOSE(...),, Nnumber_of_columns))
You can find a brief description of this one and his friends here.
I wasn't able to create a single formula that would do this for me, so instead, I utilized a formula inside of Sheets' Find/Replace tool, and it worked like a charm!
I did a find/replace, replacing all instances of TRUE with the following formula:
=INDIRECT(SUBSTITUTE(LEFT(ADDRESS(ROW(),COLUMN()),3),"$","")&"$1")
What this formula does is it finds the cell's letter, then gets the first row of the cell using INDIRECT.
Breaking down the formula:
ADDRESS(ROW(),COLUMN()) returns the direct reference: $H$1
LEFT("$H$1",3) returns $H$
SUBSTITUBE("$H$","$","") replaces the dollar signs ($) and returns H
INDIRECT(H&"$1") references the exact cell H$1
Now, I can replace all instances of TRUE with that formula and the magic happens!
Here is a video explanation: https://youtu.be/SXXlv4JHDA8
Hopefully, that helps someone -- however, I would still be interested in seeing what the formula is for this solution.

Filter a string based on a variable number of substrings in Google Sheets

I have a cell with a variable number of substrings separated by a comma.
To search:
"first,second,third"
"primero,segundo,tercero,cuarto"
"eins,zwei"
and I have a column with many strings that are composed by some of the substrings:
Column with full items
"first,second,third,fourth"
"primero,segundo,tercero,cuarto,quinto"
"primero,tercero,cuarto"
"eins,zwei,drei"
...and so on...
I would like to find the items of the Column above which has the substrings to be searched. Not a big issue when the amount of substrings is fixed but when it varies it becomes harder. I have a horrible formula that counts the number of commas and then it uses IF for each amount of substrings to search and several FIND(index(SPLIT(A4,","),2) for each substring. The formula is gigant and hard to handle.
Can you think of a better way of doing it?
Here there is an example of what I would like to do. The blue cells are the ones that should have the formula.
https://docs.google.com/spreadsheets/d/1pD9r4JF48cVSNGqA4D69lSyasWxTvAcOhWWu1xW2mgw/edit?usp=sharing
Thanks in advance!
Thank you all for your help! In the end, I used the QUERY function.
=QUERY(E:F,"select E where F contains '" & textjoin("' AND F contains '",TRUE,split(A2,",")) &"'" )
If you are interested, you can see the solution applied in the original spreadsheet :)

Return and combine all cell values from a row in Google Sheets

I have a Google Sheet and would like to return all cell values from a specific row into one cell. For example return all cell values containing the text "TBB" from row 3 without displaying the search word (TBB) and adding certain characters and a line break between each result to separate them. So the result in the cell would look like the following, where the original values are: TBB Result1, TBB Result2, TBB Result3
Result1
Result2
Result3
How can I do that? Thanks in advance.
First step is to find the cells in row 3 than begin with TBB:
filter(A3:3, regexmatch(A3:3, "^TBB"))
Second step, remove TBB and whatever whitespace follows it:
arrayformula(regexreplace([previous formula], "^TBB\s*", ""))
Third step, join the results, separating them by new lines char(10).
join(char(10), [previous formula])
All of this together:
=join(char(10), arrayformula(regexreplace(filter(A3:3, regexmatch(A3:3, "^TBB")), "^TBB\s*", "")))
Maybe with this formula in A3:
=transpose(split(substitute(A1,"TBB",""),","))
or maybe in B3:
=substitute(substitute(A1,"TBB",""),",",Char(10))

Count cells that contain any text

I want to count the cells that contain anything within a range.
Any cell that contain text, or numbers or something else should do a plus one in my result-cell.
I found this function,
countif(range; criteria)
but this doesn't work for me, because I don't know what to type in the criteria. How can I do this?
You can pass "<>" (including the quotes) as the parameter for criteria. This basically says, as long as its not empty/blank, count it. I believe this is what you want.
=COUNTIF(A1:A10, "<>")
Otherwise you can use CountA as Scott suggests
COUNTIF function will only count cells that contain numbers in your specified range.
COUNTA(range) will count all values in the list of arguments. Text entries and numbers are counted, even when they contain an empty string of length 0.
Example:
Function in A7
=COUNTA(A1:A6)
Range:
A1 a
A2 b
A3 banana
A4 42
A5
A6
A7 4 -> result
Google spreadsheet function list contains a list of all available functions for future reference https://support.google.com/drive/table/25273?hl=en.
The criterium should be "?*" and not "<>" because the latter will also count formulas that contain empty results, like ""
So the simplest formula would be
=COUNTIF(Range,"?*")
Sample file
Note:
Tried to find the formula for counting non-blank cells (="" is a blank cell) without a need to use data twice. The solution for goolge-spreadhseet: =ARRAYFORMULA(SUM(IFERROR(IF(data="",0,1),1))). For excel ={SUM(IFERROR(IF(data="",0,1),1))} should work (press Ctrl+Shift+Enter in the formula).
If you have cells with something like ="" and don't want to count them, you have to subtract number of empty cells from total number of cell by formula like
=row(G101)-row(G4)+1-countblank(G4:G101)
In case of 2-dimensional array it would be
=(row(G101)-row(A4)+1)*(column(G101)-column(A4)+1)-countblank(A4:G101)
Tested at google docs.
COUNTIF function can count cell which specific condition
where as COUNTA will count all cell which contain any value
Example: Function in A7: =COUNTA(A1:A6)
Range:
A1| a
A2| b
A3| banana
A4| 42
A5|
A6|
A7| 4 (result)
This works.
=ArrayFormula(SUM(IF(ISTEXT(put-your-range-of-text-mixed-with-anything-here),1,0),1))
IsText(range) looks at your data and returns True for every cell that is text and false for every one that is not. I think these are returned into a data table/array. See step 4.
If(IsText(range),1,0) takes the True/False values from the array/table returned by IsText in step 1, and translates the Trues into 1's and the Falses into 0's, as true integers, not strings.
Sum(range) then totals the 1's (Trues/Cells that are entirely text) and ignores the 0's (Falses/Cells not entirely text).
For some reason, ArrayFormula is needed to return the sum of all cells back into one cell, rather than returning the sum of all cells into a table of equal size. Idk. Would appreciate it if someone knowledgable could please add to this.
Bon chance.
to count any cells that has anything in it (including any text or number values, and also formulas that have text or numeric or blank results), then use:
=COUNTIF(A1:A10, "<>")
or
=COUNTA(A1:A10)
to count only cells that have a value that is NOT blank (including text or numeric values, or formulas that have numeric or text values, but NOT including formulas that have blank results) ie: cell value is longer than zero characters, then use:
=SUMPRODUCT(--(LEN(A1:A10)>0))
or
=COUNTA(FILTER(A1:A10, A1:A10 <> ""))
to count only cells that have a text (alphanumeric) value, then use:
=COUNTIF(A1:A10,"?*")
to count only cells that have a numeric value, then use:
=COUNT(A1:A10)
to count any cells that are blank (including cells that have no value, and cells where the formula result is blank), then use:
=COUNTBLANK(A1:A10)

Resources