Where to nest trim into a google sheet formula? - google-sheets

I am stuck trying to find how to put trim into a function to remove blank answers from a query on a column of cells
=IFERROR(INDEX(TRANSPOSE(QUERY(TRANSPOSE(IF(LEN(SPLIT(REGEXREPLACE(N3&" ","\D+"," ")," "))=11,
SPLIT(REGEXREPLACE(N3&" ","\D+"," ")," "),"")),"where Col1 is not null ",0))),"")
got me to extract the numbers from a mix of numbers and letters in a list but has left
Column A
12345678912
12345678912
id like for it to pull up and end up like
Column A
12345678912
12345678912

try:
=FILTER(N:N, LEN(N:N)=11, NOT(ISDATE_STRICT(N:N)))

Related

google sheet query error AVG_SUM_ONLY_NUMERIC

Hi I use this query formula in google sheet and it works good as long as there is values in column E,F,G.
=Query('CM Invoice Report'!A10:G,"Select C,Sum(E),Sum(F),Sum(G) where C is not null Group By C Label C'', Sum(E)'', Sum(F)'', Sum(G)''",0)
The problem is if one of the column as no value I get #VALUE AVG_SUM_ONLY_NUMERIC error so I tried adding an iferror to the formula as suggested in many post but I just can't seem to get it to work.
PS. I've also tried replacing column C,E,F,G with Col3,Col5,Col6,Col7 and still nothing.
Here's the other formula I've tried.
=Query({Iferror(query('CM Invoice Report'!A10:G,"Select C,Sum(E),Sum(F),Sum(G) where C is not null Group By (C) Label C'', Sum(E)'', Sum(F)'', Sum(G)''",0),{"","","",""})})
Any help would be greatly appreciated
It's possible that in one of the columns you have many text values? If that's so, QUERY is possibly handling that column as text, considering the actual numbers as text. You may try converting them to its numeric value; IFERROR will exclude those that are really text:
=Query({'CM Invoice Report'!C10:C,INDEX(IFERROR(VALUE('CM Invoice Report'!E10:G)))},"Select Col1,Sum(Col2),Sum(Col3),Sum(Col4) where Col1 is not null Group By Col1 Label Col1 '', Sum(Col2) '', Sum(Col3)'', Sum(Col4)''",0)

Finding the first value in a row and getting the address using ArrayFormula

in this example table, I want to get the first "failed" or "passed" from result 1, 2, and 3 column. I already made a formula to get the first mentioned value using:
=IF(C2=C2,CELL("address",INDEX(D2:F2,MATCH(C2,D2:F2,0))),)
which works fine (the column result is from that formula)
But when I'm trying to use ArrayFormula on the formula, it only shows the first row value only. my ArrayFormula is like this:
=ArrayFormula(IF(C2:C4=C2:C4,CELL("address",INDEX(D2:F2,MATCH(C2:C4,D2:F2,0))),))
i think its because the INDEX and MATCH doesn't update as it goes down, any idea how to fix this?
Sheets link: https://docs.google.com/spreadsheets/d/1oFTZHGd9PKpfZ9QXWvTshorEOGFxmD1cpeeQ9bIOYh8/edit?usp=sharing
You could use a query to get the minimum column matching the value in column C for each row in D to F:
=ArrayFormula(lambda(a,address(index(a,,1),index(a,,2)))
(query(split(flatten(if(C2:C="",,if(D2:F=C2:C,row(C2:C)&"|"&column(D2:F),))),"|"),"select Col1,min(Col2) where Col2 is not null group by Col1 label min(Col2) ''")))
Or alternatively you can use a formula similar to your original one with Byrow:
=ArrayFormula(if(C2:C="",,byrow(C2:F,lambda(r,CELL("address",INDEX(r,1+MATCH(index(r,,1),index(r,,2):index(r,,columns(r),0))))))))

Google sheets question - filter sum equation

I have a list of email addresses in one sheet (first column).
I have a list of transactions in another sheet with emails and sale amounts.
I am looking for a formula that adds up all the transaction $ sales for any transactions made by the people (emails) in the first sheet.
Any help would be much appreciated!
Your sample data is very limited (only one row matching one person, in fact). But the following formula should work for you. Place it in a new sheet, in cell A1:
=ArrayFormula(IFERROR({"Name","Total"; QUERY(FILTER(Transactions!A2:D,NOT(ISERROR(VLOOKUP(Transactions!A2:A,Tags!A:A,1,FALSE)))),"Select Col2, SUM(Col4) GROUP BY Col2 ORDER BY Col2 LABEL SUM(Col4) '' ")},"No Data"))
This one formula will produce the headers (which you can change within the formula itself as desired) and all results.
FILTER filters in only 'Transactions' data (names through amounts) where the emails are found in the 'Tags' sheet.
Then QUERY returns the name and totals for each match in alphabetical order by name.
If there are no matches, "No Data" will show instead.
If I understood your question correctly!
Try this on the sheet, where you only have emails and wanted to get sum of sales amount
=sumifs(range_whichHasTransaction , range_of_Email_inThat_TransactionsTable , Cell_Reference_ofEmail_forWhich_you_want_sum_the_Transaction_Amount)
it will Look something like this:-
sumifs(TransactionSheet!B:B,TransactionSheet!A:A,Emails!A2)
Reference
SUMIFS

Google Sheets Query Coalesce?

is there any query syntax that woks like coalesce in google sheets?
if i have a source like pict below
the result i want is only getting id and time if status is true, but the time is only exist in one col either in check column or report column
so the result would be like this...
I tired this but doesn't work
=QUERY(A1:D4, "SELECT A, COALESCE(B, C) WHERE D = TRUE")
any ideas or workarounds?
Thanks
try:
=ARRAYFORMULA(IFERROR(SPLIT(FLATTEN(QUERY(TRANSPOSE(
ARRAY_CONSTRAIN(IF(D2:D=TRUE, {A2:A, IF(B2:C="",,"×"&B2:C), D2:D}, ), 9^9,
COLUMNS(A:C))),, 9^9)), "×")))
A very short one just for the special case of 2 columns where you know that only one of them is populated and they are dates:
=ArrayFormula(to_date(if(D2:D,B2:B+C2:C,)))
Maybe the simplest formula which behaves like coalesce would be
=iferror(if(D2,hlookup(9^9,B2:C2,1,true),))
It's just a pull-down formula but will pick up the first non-blank column from a range of columns containing numbers or dates. If the columns are all blank, it returns blank.
You can take advantage of the either or situation and concatenate the 2 columns.
=filter({A2:A,concat(B2:B,C2:C)},D2:D)
Also see local array and filter
Add a column after Status call it Time (column E), whereas each formula follows this format (assuming your table starts at A3:E)
=if(A4="","",if(B4<>"",B4,C4))
Now query A3:E like so,
=query(A3:E,"Select A,E where D=TRUE")
you can use something like this:
=QUERY(transpose(B1:H1),"Select Col1 where Col1 is not null limit 1",0)
This transposes the row into a column, queries all non-null values from that column, and then set limit 1 to return the first value. So essentially you are selecting the leftmost non-empty value from your row.
I can't take full credit for this, I must have gotten it somewhere else... but it's in one of my sheets.

google sheets, Make letters separated by comma given number of following columns. Not using app script, just formulas please

I'm using the query function in google sheets... I want to select columns F to AB.
I need a cell that has the output F,G,H,I... ,AB so I can put it in the Select statement.
This formula should have 2 inputs, the starting letter (F in this case) and number of following columns (22 in this case)
No app script code please. I know someone can do it with just formulas in one cell.
I believe your goal as follows.
You want to create the value of F,G,H,I... ,AB by giving the start column letter of "F" and the number of columns of 22.
For example, when the start column letter of "F" and the number of columns of 22 are given, you want to retrieve the value of F,G,H,I... ,AB and you want to use this like =QUERY(A1:AB,"SELECT F,G,H,I... ,AB").
You want to achieve this using the built-in functions of Google Spreadsheet without the Google Apps Script.
For this, how about this answer?
Sample formula 1:
In this sample formula, in order to create the value of F,G,H,I... ,AB by giving the start column letter of "F" and the number of columns of 22, I would like to propose the following formula.
=TEXTJOIN(",",TRUE,ARRAYFORMULA(REGEXREPLACE(ADDRESS(1,COLUMN(INDIRECT(A1&"1:"&ADDRESS(1,B1+COLUMN(INDIRECT(A1&"1")),4))),4),"\d+","")))
When A1 and B1 have the values of F and 22, respectively, the flow of this formula is as follows.
Using COLUMN, retrieve the column numbers.
Using ADDRESS, retrieve the column letters from the column numbers. At that time, the row number os removed using REGEXREPLACE.
Above formulas are used with ARRAYFORMULA.
Using TEXTJOIN, join the column letters with ,.
Result:
Sample formula 2:
In this sample formula, =QUERY(A1:AB,"SELECT F,G,H,I... ,AB") is created using above sample formula 1.
=QUERY(A1:AB,"SELECT "&TEXTJOIN(",",TRUE,ARRAYFORMULA(REGEXREPLACE(ADDRESS(1, COLUMN(INDIRECT(A1&"1:"&ADDRESS(1, B1 + COLUMN(INDIRECT(A1&"1")), 4))), 4),"\d+",""))))
Result:
In this sample result, the range of A2:AB7 is used for QUERY. So please be careful this. When the cells "A1" and "B1" are changed, the result of this formula is also changed.
Note:
In this case, when the start column and the number of columns are more than the existing maximum columns, an error occurs, please be careful this.
References:
COLUMN
ADDRESS
REGEXREPLACE
ARRAYFORMULA
TEXTJOIN
Added:
When you want to create Col6, Col7, Col8 ... Col28 by giving the start column letter of "F" and the number of columns of 22, how about the following sample formula?
Sample formula:
="Col"&TEXTJOIN(",Col",TRUE,ARRAYFORMULA(COLUMN(INDIRECT(A1&"1:"&ADDRESS(1,B1+COLUMN(INDIRECT(A1&"1")),4)))))
In this case, please put F and 22 to the cells "A1" and "B1", respectively.
if your range is F:AB then you can skip select parameter or use:
=QUERY(F1:AB; "select *"; 0)
if the range is larger put the range in curly brackets and try:
=ARRAYFORMULA(QUERY({A1:AB}; "select "&TEXTJOIN(","; 1; "Col"&COLUMN(F:AB)); 0))

Resources