I am trying to get sum of two columns using Query function and am getting perfect result when all the two columns have value, however, if any of the column is not having a value than the result will be blank. In such a case I want to reflect the value of the second column having data. Check the below image:
Formula used =QUERY(A2:C,"select A,B+C label B+C ''",0)
Sharing the link of the sheet too for reference.
https://docs.google.com/spreadsheets/d/1TID_7m6MTNviLkU0dlPoCDyA8Uv9Iann2WtCYL9CJQo/edit#gid=0
Any help on above will be appreciated.
I had also searched community for similar issue but not found the exact match.
Give a try on below formula-
=QUERY({A2:A,INDEX(IF(B2:C="",0,B2:C))},"select Col1,Col2+Col3 where Col1 is not null label Col2+Col3 ''")
Here IF(B2:C="",0,B2:C) will convert null cells to zero 0 values.
try:
=INDEX({A2:A4, B2:B4+C2:C4})
Related
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)
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))))))))
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.
I'm sure this is possible, but I've been trying various ways for the past 2 hours and can't find the solution.
I need to find all the instances of a text name in column A, lookup all the numerical results in column B and sum them together.
I thought =ArrayFormula(sum(lookup(F2,$A$2:$B$1000))) would do the trick, but it's only picking up the last value on the last mention and not all the values of all the mentions.
I've attached a spreadsheet to show the data I'm looking at.
Thanks to the reference from BigBen to check out Sumifs. Using this command, the following works a treat:
=SUMIFS(B2:B3115,A2:A3115,F2)
try:
=QUERY(A2:B; "select A,sum(B) where A is not null group by A label sum(B)''")
I've been at this problem for a while now. I am trying to sum numbers under a specific column when the rows equal a certain text and then display that sum on a different sheet. So far I came up with this formula: =IF(EXACT(A2,Table!A2:A)=TRUE,SUM(Table!C2:C)); however the only problem is that is sums everything in column C (which makes sense).
I wish there was a way to do something like the following: SUM(Table!C2:C where EXACT(A2,TABLE!A2:A)=TRUE). I've also tried the SUMIF(), DSUM(), and QUERY() functions to no avail. I must be getting logically tripped up somewhere.
Figured it out: =SUM(FILTER(Table!E4:E, EXACT(Table!A4:A,A4)=TRUE)).
=sum ( FILTER (b1:b10, a1:a10 = "Text" ) )
// the above formula will help you to take the sum of the values in column B when another column A contain a specific text.
The formula is applicable only in Google Spreadsheets