I asked this before but I can't for the life of me find that question, so I just have to assume it dissolved into the ether.
I have this SUM function =SUM(QUERY($A$1:$B, "SELECT B WHERE A = '" & "s" & "'", 0)) that works just fine when used on one sheet, but not on another sheet in the same spreadsheet. In the other spreadsheet, it returns a zero rather than the total that it's supposed to. Through some experimenting, I've found that reducing the query search range seems to fix the problem, but that is unhelpful to me as the new range is smaller than what I need. If anyone knows anything about this or any possible fixes, some help would be super appreciated!
Here is a copy of the spreadsheet in question, all cells containing the formula are highlighted yellow: https://docs.google.com/spreadsheets/d/1bNmDYdUw-FU4wWTShV1cijtOt9l7McvktgAoDELbwQ8/edit?usp=sharing
If any more info is needed feel free to ask! Thank you!
Problem is in your K Column formula. The formula returning text instead of numeric number which causing trouble QUERY() formula. Change this formula =IF((E2*F2*H2)>0, Roundup(((E2/F2)+(E2/H2))/2, 3), "-") to
=IF((E2*F2*H2)>0, Roundup(((E2/F2)+(E2/H2))/2, 3), 0)
You can directly use avg() function to query formula to get average. Try-
=QUERY($B$2:$M, "SELECT avg(K) WHERE B = 's' label avg(K) ''", 0)
use:
="Average: "&AVERAGEIF(B2:B, "s", K2:K)
Related
I would like to know what product I exactly have with this sheet. So I add in column O for help. However, my formula seems to be too long to maintain in the future, and it will always have a "/" in the end.
This is my formula in O2
=if(isblank($A2),,$A$1&"/")& if(isblank($B2),,$B$1&"/")& if(isblank($C2),,$C$1&"/")& if(isblank($D2),,$D$1&"/")& if(isblank($E2),,$E$1&"/")& if(isblank($F2),,$F$1&"/")& if(isblank($G2),,$G$1&"/")& if(isblank($H2),,$H$1&"/")& if(isblank($I2),,$I$1&"/")& if(isblank($J2),,$J$1&"/")& if(isblank($K2),,$K$1&"/")& if(isblank($L2),,$L$1&"/")& if(isblank($M2),,$M$1&"/")&
How could I improve this forluma? Thanks!
You need TEXTJOIN() and FILTER() function.
=TEXTJOIN("/",1,FILTER($A$1:$N$1,A2:N2=1))
to process the whole array at one use:
=IFERROR(BYROW(A2:N, LAMBDA(x, TEXTJOIN("/", 1, FILTER(A1:N1, x<>"")))))
This question is also answered here:
Get a vlookup of a cell after split in Google sheet
but not marked as corrected answer, and cannot make it work.
Goal : I want to apply a vlookup function to a split function, so that I can search for corresponding values (found by the vlookup) for each token obtained from a string.
Consider this sheets:
// Sheet 'veggies'
A
apple, pine, tree
pine
// Sheet 'themes':
A
B
C
apple
8
theme1,theme2
tree
3
theme2
pine
1
theme1,theme3
I want to:
split cells of column A of 'veggies' by commas, so to have tokens
vlookup for the C column in 'themes' sheet, by using the index of tokens, for all of them
As approach I tried to first retrieve the frequences of tokens in column B, sheet 'themes', and cannot understand what my formula is doing:
=ARRAYFORMULA( VLOOKUP( split(A2;",");'themes'!A$2:D;2;FALSE))
This formula only get the frequency from column be for the first token, while for others will only report N/A saying could not find a value, but it is clearly there.
Any help?
Am I on the right track ?
P.s. if one would like to offer use of query , like in the other SO answer, please help me to break down what it does.
ARRAYFORMULA( VLOOKUP( split(A2;",");'themes'!A$2:D;2;FALSE))
Your formula works. But when splitting by comma , there's a extra space left over in all the elements from the second element. So, when
apple, pine, tree is splitted, it becomes apple, pine, tree(note the extra space prefix). To fix, you can simply add a space to the split as well:
=ARRAYFORMULA( VLOOKUP( split(A2;", ");'themes'!A$2:D;2;FALSE))
this should work if you want the results in one cell.
=ARRAYFORMULA(TEXTJOIN(", ";TRUE;IFERROR(VLOOKUP(SPLIT(A2;", ";0);themes!A:C,2,0))))
Use this formual
=ArrayFormula(LAMBDA(v,
IF(v="",,{v,SPLIT(VLOOKUP(v,themes!A2:C,3,0), ", ",1)}))
(FLATTEN(IF(A2:A="",,SPLIT(A2:A, ", ", 1)))))
First of all, i'm not a powerful sheets user :)
I'm trying to use GOOGLEFINANCE to calculate amounts in multiple currencies.
I use this formula:
=IF($A2;
IF(
$C2:C;
$C2:C;
IF(
$D2:D;
$D2:D*INDEX(GoogleFinance("CURRENCY:USDUAH";"close";$A2);2;2);
$E2:E*INDEX(GoogleFinance("CURRENCY:EURUAH";"close";$A2);2;2)
));
0)
A-column contains dates,
C,D,E - amounts in 3 different currencies.
IFs are just to prioritize columns :)
The formula works well but i need to "extend" it each time i add row - to increment
$A2 -> $A3 to get rate for specified date.
I try to use ArrayFormula but it turns out it keeps reference to $A2 so i get same rate irrelevant from date specified in A-cells.
I have created sample sheet to illustrate:
https://docs.google.com/spreadsheets/d/1K2TbGIWl7JacYKiWgwwmJfelxJ-7fa9F9obp5XswW18/edit?usp=sharing
I have allowed editing by anyone, so if you decide to edit - please don't remove anything :) also you can drop your username in sticky row(above your proposed solution)
Is there a way to apply ArrayFormula to this to make it work?
Maybe you can provide more readable solution to nested IFs.
try:
=ARRAYFORMULA(IF(A2:A<>"";
IF(C2:C<>""; C2:C;
IF(D2:D<>""; VLOOKUP(TO_TEXT(A2:A);
TO_TEXT(QUERY(GOOGLEFINANCE("CURRENCY:USDUAH";
"close"; MIN(A:A); MAX(A:A)+1);
"offset 1 format Col1'dd.mm.yy'"; 0)); 2; 0)*1;
VLOOKUP(TO_TEXT(A2:A);
TO_TEXT(QUERY(GOOGLEFINANCE("CURRENCY:EURUAH";
"close"; MIN(A:A); MAX(A:A)+1);
"offset 1 format Col1'dd.mm.yy'"; 0)); 2; 0)*1)); ))
There is a new simpler and more flexible method now since the introduction of LAMBDA and its helper functions in Google Sheets in August 2022.
Assuming dates in A2:A, and amounts in UAH, USD, EUR in C2:C, D2:D, E2:E respectively, then the following formula will work, e.g. in cell F2:
=MAP(A2:A;C2:C;D2:D;E2:E;
LAMBDA(date;uah;usd;eur;
IFS(
uah;uah;
usd;usd*INDEX(GOOGLEFINANCE("currency:usduah";"price";date);2;2);
eur;eur*INDEX(GOOGLEFINANCE("currency:euruah";"price";date);2;2);
ISBLANK(date);)))
The trick here is that MAP(LAMBDA) calculates the specified formula for each row of the input array separately (effect similar to manually expanding the formula over the whole range), whereas ARRAYFORMULA passes the whole array as an argument to the formula (GOOGLEFINANCE is special and doesn't work intuitively with such input).
This general method with MAP(LAMBDA) can now be used to pass any arguments to GOOGLEFINANCE in a way one would otherwise expect to do with ARRAYFORMULA.
Try This One:
=arrayformula(
IF(query(arrayformula(if(A2:A="",False,True)),
"Select * where Col1=True"),
IF( $C2:C,
$C2:C,
IF( $D2:D,
$D2:D*INDEX(GoogleFinance("CURRENCY:USDUAH","close",$A2),2,2),
$E2:E*INDEX(GoogleFinance("CURRENCY:EURUAH","close",$A2),2,2))),0))
I would like to modify the following QUERY, or some formula variation that accomplishes the same result, to only be entered a single time at the top of the column and fill the cells below using ARRAYFORMULA
=IFERROR(QUERY(Items!$A$2:$T,"SELECT E,F,G,H,I,J,K,L,M,N,O,P,Q,R where A = '"&Estimate!A2&"' and B = '"&Estimate!B2&"' and C = '"&Estimate!C2&"' "&if(Estimate!D2<>"", "and D = '"&Estimate!D2&"'",)&" AND A is not null LIMIT 1", 0),"")
My formula is in Estimate!G2 of my spreadsheet.
this answer is pretty much correct, tho the exact formula would be:
=ARRAYFORMULA(IF(LEN(A2:A), VLOOKUP(A2:A&B2:B&C2:C&IF(LEN(D2:D), D2:D, "*"),
{Items!A2:A&Items!B2:B&Items!C2:C&Items!D2:D,Items!A2:T},
{6,7,8,9,10,11,12,13,14,15,16,17,18,19}, 0), ))
I think you'd have to use Vlookup, which isn't quite as convenient as Query. This is what I have so far, but it might need a bit more work to get exactly the same results as query in all cases (owing to the ORDER statement within the query):
=ArrayFormula(if(A2:A="","",vlookup(A2:A&B2:B&C2:C&if(D2:D="","*",D2:D),{Items!A2:A&Items!B2:B&Items!C2:C&Items!D2:D,Items!A2:T},{2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21},false)))
I've been struggling with this Spreadsheets query problem for hours and even after rigorous googling, couldn't figure out what's wrong or how to do this properly. Here's an example of the problem:
=QUERY('Sheet2'!2:3, "select B where A="A2"")
Example Spreadsheet: https://docs.google.com/spreadsheets/d/172kaXIs0-OhWxhvI65OvnfM1jiLt6OdQVrGYDjxf6V8/edit?usp=sharing
What I'm trying to do is pull data from the Sheet2 so that I can also include the A2 cell from Sheet1 in the equation for better automation. I know there's a way to do it but I just can't seem to be able to make it work.
The syntax is two pairs of quotes (each a single and a double) around concatenation with &. Please try:
=QUERY(Sheet2!2:3, "select B where A='"&A2&"' ")
Your version should work if the actual content of A2 were A2.