EXCEL/Google Sheets. Best way to SUM multiple VLOOKUP? - google-sheets

could you guys help me with a project. I was able to find a solution for my problem and the formula looks like this:
=IFERROR(VLOOKUP(E4;A8:B13;2;FALSE);0)+IFERROR(VLOOKUP(F4;A8:B13;2;FALSE);0)+IFERROR(VLOOKUP(G4;A8:B13;2;FALSE);0)
I have a category (e.g. Fruits) and need to import a sheet with different kind of fruits and non fruits. I use keywords which define what is a fruit and what not. I need to SUM all values which match to a keyword. My formula works but it will be more and more work when i need to add more keywords.
Are there a better way to realise this?
I build this example sheet for better understanding : )
Spreadsheet link
Thank you in advance : )

use:
=SUMPRODUCT(IFNA(VLOOKUP(E4:G4; A8:B13; 2; )))
you can even use E4:4 or E4:G5 or E4:5
row-wise it would be:
=INDEX(BYROW(E4:G5; LAMBDA(x; SUM(IFNA(VLOOKUP(x; A8:B13; 2; ))))))

use this
=ArrayFormula(SUM( IFERROR( VLOOKUP(E4:G4;A9:B;2;0))))
Usign sumif
=ArrayFormula(SUM(SUMIF(A9:A;"="&E4:G4;B9:B)))
Xlookup
=ArrayFormula(SUM(XLOOKUP(E4:G4;A9:A14;B9:B14;"";1)))

Us XLOOUP instead of IFERROR(VLOOKUP()) can shortens the formula.
=SUMPRODUCT(XLOOKUP($E4:4,$A$9:$A,$B$9:$B,0))

Related

How to make this formula shorter in google sheets

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<>"")))))

Using query in google sheet to call certain rows

Hi everyone,
I want to get all the rows where A=1, A=2. The query is very simple but I'm not sure why there is no output. I guess is the problem of the format for column A but I'm not sure what should I change in my formula so that the formula can work. Appreciate any help or advice!
A can't be both: 2 and 1. Instead try
=query(A3:C, "Where A = 2 or A = 1", 0)
It should have been OR not AND - it's impossible for any row in a particular column to have two values simultaneously:
=query(A3:C,"select * where A=1 or A=2",0)
QUERY() is good choice. You can also use FILTER() function like-
=FILTER(A3:C,A3:A>=1,A3:A<=2)

How to extract text from cells with distinct

I tried different approaches to accomplish what I am looking for and it might not be possible with how I have formated my data but I will try to explain it to see if there is a way.
My origin of data looks like the following:
Case
HELP
100
HELP-01
HELP-02
101
HELP-01
102
103
HELP-03
What I want is to be able to extract the HELP-* into another column without duplicate values and one after another. The result I am looking for is from the above table been able to have this:
HELP
HELP-01
HELP-02
HELP-03
Is there a way to do this in Google Sheets?
Thank you,
Alternatively you can use:
=UNIQUE(QUERY(FLATTEN(B2:C),"where Col1 like 'HELP-%'"))
The QUERY() will now only return those values that start with 'HELP-' in the case you might have other string-values.
A littel more specific even, could be to use:
=UNIQUE(QUERY(FLATTEN(B2:C),"where Col1 matches 'HELP-\d+'"))
Where 'matches' will now use the regular expression to only return values that start with 'HELP-' but end with any 1+ digits.
Try this in Google Sheets
=sort(array_constrain(unique(flatten(B2:C)),counta(B2:C),1))

What method can filter two pairs of data using filter() or other recommanded way?

I want to use filter() to search from B2:B corresponding to
the range like F2:F3
I use =filter(A2:A,B2:B = F2:F3),but there is just one data Jack
I know this example can using FILTER to do the same thing like this.
But now if there is a lot of data, it may not meet my needs.
Then I use =ArrayFormula(filter(A2:A,B2:B = F2:F3))
And it's not useful, too. (I don't know how to use arrayformula() methods)
What should I fix the formula and parameters?
Use COUNTIF to check whether the values B2:B are included in the range F2:F3:
=FILTER(A2:A,COUNTIF(F2:F3,B2:B))
try:
=FILTER(A2:B; REGEXMATCH(B2:B; TEXTJOIN("|"; 1; F2:F)))
or:
=QUERY(A2:B; "select A,B where B matches '"&TEXTJOIN("|"; 1; F2:F)&"'"; 0)

Importrange() where the source columns/rows change

I have an importrange("key", "sheet1!D" & targetRow) formula, but I also need the column of the importrange() to be dynamic too in case I add/delete columns in the source data:
E.g. importrange("key", "sheet1!" &targetColumn &targetRow)
I researched query() language but being forced to use Col1, Col2 etc instead of named column identifiers makes this useless for what I'm trying to achieve.
Can someone help me with this? Easiest way to get column letters without a script? Thanks very much.
I've figured out a somewhat inelegant workaround:
=IMPORTRANGE("key", "Sheet!" & IMPORTRANGE("key", "Dept") & targetRow)
Where "Dept" is a single-cell named range that contains the column letter of the column I want.
The column letter (e.g. 'K') is the result of the following formula:
=substitute(address(row(K6), column(K6),4), row(K6),"")
Is there really no easier/more robust way of doing this? This will be used to calculate bonuses so it's actually a very critical spreadsheet.

Resources