I have been receiving an error while using AverageIFS function the error is Evaluation of function AVERAGEIFS caused a divide by zero error.
I am matching 4 columns where it gives error but when use for three it works fine.
=AVERAGEIFS(Sheet1!$C:$C,Sheet1!$A:$A,D3,Sheet1!$B:$B,$A$2,Sheet1!$D:$D,$B$2,Sheet1!$D:$D,$B$3)
Link to Sheet:
In cell G2 of Sheet 2 I entered
=query(Sheet1!A:D, "Select A, avg(C) where B ='"&A2&"' and D matches '"&textjoin("|", true, B2:B3)&"' group by A label avg(C) 'Average'", 1)
As an alternative for your current solution you can try
=AVERAGE(FILTER(Sheet1!$C:$C,Sheet1!$A:$A=D3,Sheet1!$B:$B=$A$2,( (Sheet1!$D:$D=$B$2) + (Sheet1!$D:$D=$B$3))))
and drag down.
The current solution does not work because there are no rows where all conditions are met. E.g: Column D can't contain 'PAF' and 'PAN'.
See if that works for you?
Related
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))))))))
I have a google sheet (Final Calculation) where I am trying to get sum of all values in Column G (in Data tab) against a set of values in Column B, L and D (in Data tab). However, condition for values in Column D is dynamic and would likely change every month. I have created a tab Advertiser List where the condition for filter in Column D gets updated. How, do I use this condition in Query function used in C5 cell in Final Calculation tab?
I tried referencing the condition in Advertiser List sheet using indirect but I am getting an error. I have also added a hard coded formula is other cells in Final Calculation tab to show what am I trying to achieve.
Below is the formula that I have written and is showing an error:
=iferror(QUERY(Data!$A:$L, "Select Sum(G) where B = '"&$B5&"' and L = '"&C$3&"' and indirect('"Advertiser List"'&'"!"'&'"D2"') label sum(G)'' "),0)
Here is the link of the Google Sheet (Link)
You don't need INDIRECT to get a text value from another tab:
=QUERY(Data!$A:$L, "Select Sum(G) where B = '"&$B5&"' and L = '"&C$3&"' and (" & 'Advertiser List'!D1 & ") label sum(G)'' ")
When in doubt, try to build the "select ... " string in a separate cell until you see the expected result. Then wrap it with query and check again. Adding IFERROR should always be your last step, because you will want to see the errors that your query is throwing.
I'm trying to count instances of letters (like letters C through Z, excluding RR) within the same column if they are listed next to a name. Here's my sample Google Sheet that you can edit.
I'm trying to insert the formula in cell F3 that is highlighted yellow. So far I have...
=arrayformula(SUM(COUNTIFS(A2:A,{"C","D","E","F","G"},C2:C,E3:E)))
It seems like what I have should work, but it's giving me a #VALUE error, saying, "ARRAY arguments to COUNTIFS are of different size".
It seems like REGEXMATCH could be used inside the COUNTIF formula to make it easier to restrict the search to the range of letters I need, but not sure how to construct the formula.
Thanks for your help!
UPDATE
This formula below works but only for column A. I actually need to specify a different range of letters to be counted in column B and totaled in column K.
=QUERY(A2:C,"select C,count(A) where A matches 'C|D|E|F|G|H|I|J|K' group by C label count(A)''", 0)
Seems like this post almost answers it.
Current progress:
={QUERY(A2:C,"select C,count(A) where A matches 'C|D|E|F|G|H|I|J|K' and A is not null group by C label count(A)''", 0),QUERY(A2:C,"select count(B) where B matches 'F|G|H|I|J|K' and B is not null group by C label count(B)''", 0)}
As we have discussed / tested on your sample sheet. This should work as close as possible to the data that you would want to filter/display.
A 2-formula solution was found to work as well. Answer is in the same spreadsheet linked above in Sheet2. It should prevent the first formula from not working should someone need a different one.
J2 - =QUERY(A2:C,"select C,count(A) where A matches 'C|D|E|F|G|H|I|J|K' group by C label count(A)''", 0)
L2 - =ArrayFormula(IFNA(vlookup(J2:J,QUERY(A2:C,"select C,count(B) where B matches 'F|G|H|I|J|K' group by C label count(B)''", 0),2,0)))
This formula should work for you if you paste it in cells F3 to F7.
I currently have cells P1 to P26 (you'd probably want to hide this column) occupied with the letters of the alphabet in order, making it so that you can select P3:P26 (C-Z) to put into your first condition for your COUNTIFS.
=arrayformula(SUM(COUNTIFS(A2:A, $P$3:$P$26,C2:C,E3)))
You'll have to implement these formulas in the other places that you want them too, but it shouldn't be hard to change this formula to work in the other places as well.
I want to construct a Query that takes data from multiple sheets and lists the contents of them all. All sheets have the same variables and should, therefore, be combined. When typing in 0 as the last argument of the query I always receive an error.
I am using the following formula and have tried to input 0 as well as FALSE as the last argument. Every time I received an error. In addition to this, I tried including label AI '' at the end of the statement which worked but I could not seem to also have a blank for AJ. Furthermore, I suspect that the blank spaces will still be shown which I don't want.
={QUERY(PRIO!A:AX, "select D, E where B matches 'Negative' order by D");
QUERY(collated!A:AJ, "select AI, AJ where AG matches 'Negative' order by AJ")}
not sure what went wrong because you didn't provide a copy of your sheet but try:
={QUERY(PRIO!A1:AX, "select D, E where B matches 'Negative' order by D", 1);
QUERY(collated!A2:AJ, "select AI, AJ where AG matches 'Negative' order by AJ", 0)}
I understand how to do arithmetic on a column using a query function as long as I'm using a fixed constant. However, if I try to do the same using a cell reference instead of a constant, I get an error.
I've tried making the cell a named range and referring to that name hoping it would act like a constant but I still get errors. There must be a way to do this. Here are examples of things that work:
=QUERY(FebMarket,"SELECT (C/5)") //This divides column C by 5
=QUERY(FebMarket,"SELECT AVG(C)") //This gives me the average of column C
=QUERY(FebMarket,"SELECT AVG(C) LABEL AVG(C) ''")
//average of col C without a header
However, if I do any of the following I get an error:
=QUERY(FebMarket,"SELECT C/(AVG(C) LABEL AVG(C) '')")
=QUERY(FebMarket,"SELECT C/(AVG(C))")
=QUERY(FebMarket,"SELECT C/AVG(C)")
=QUERY(FebMarket,"SELECT C/avgC") // where 'avgC' is a named range given to a cell where I calculated the average of column C separately
=QUERY(QUERY(C1:C,
"select C / "&AVERAGE(C1:C), 0),
"select Col1
where Col1 is not null
label Col1 '' ", 0)
As far as I know you get the same result in all dialects of SQL. You can do one of two things in a single query:
Get the result of an aggregate (like AVGE) over the entire dataset
e.g.
=QUERY(FebMarket,"SELECT AVG(C)")
in which case you can only select aggregates in the query
or
Get an aggregate for each one of a set of groups defined by one or more grouping variables.
e.g.
=QUERY(FebMarket,"SELECT GroupVariable,AVG(C) group by groupVariable")
in which case you can select grouping variables and aggregates in the query.
Neither of these help.
If you google something like 'SQL divide column by its average' you will probably get an answer using a subquery but at time of writing these are not available in Google Sheets.
So (although you could do this shorter by other means) the solution using queries would have to be
=ArrayFormula(query(A:A,"select A where A is not null")/query(A:A,"select avg(A) label avg(A) ''"))