Gsheet - Arrayformula function to include 2 conditions (AND operator) - google-sheets

The goal is to create an arrayformula that looks over two separate columns and returns a SUM if it matches a certain string.
Here's an example table:
Feature
Status
Description
API
Completed
Lorem ipsum
Database
In review
lorem ipsum
Server
Backlog
lorem ipsum
Load Balancer
Completed
lorem ipsum
DB
QA
lorem ipsum
LB
Completed
lorem ipsum
Data base
Backlog
lorem ipsum
The first thing I wanted to pull, was the total number of Data base entries, regardless of the spelling. Which works
For that I used:
=ArrayFormula(Sum(CountIfs(A2:A8, {"db","data b*","database"})))
On that note: I know that's not scalable to keep adding different string variations, it's a one-off-scenario.
What I'd like to return is "For all Database entries, return the SUM where status = Completed". Which would be 0 in this scenario.
I tried adding another arrayformula into the above but I'm not sure how to reference only those items found in the previous formula? If that makes sense?
To visualise the confusing explanation:
=ArrayFormula(Sum(CountIfs(A2:A8, {"db","data b*","database"}) AND "WHERE STATUS IS COMPLETE"))
Could someone point me into the right direction? I'm happy to read through any documentation (only started looking at excel formulas today for the first time)

try:
=SUMPRODUCT(B:B="completed", REGEXMATCH(A:A, "(?i)database|db|data b"))

Related

Automatically add rows in google sheets when importing data from other sheets

I am trying to import data from several sheets into one, But they need to come between data in other cells.
So i have:
Fixed text data 1
=FILTER('Car Parks'!A:AC, NOT(ISBLANK('Car Parks'!A:A)))
=FILTER('Chapter 8'!A:AC, NOT(ISBLANK('Chapter 8'!A:A)))
=FILTER('Production'!A:AC, NOT(ISBLANK('Production'!A:A)))
=FILTER('CSAS'!A:AC, NOT(ISBLANK('CSAS'!A:A)))
Fixed text data 2
However, each of the FILTER functions will return a #REF as it cannot overwrite the other FILTER functions or the fixed text data.
Each filter function works correctly as long as there is not too many rows required.
Is there a straight forward way to allow each of these FILTER functions to add rows until they are completed, before the next filter function or fixed text data?
Context:
Used to generate a quote document.
Each Filter function imports shift timings for different sectors on a job
Fixed text data 1 is the initial data such as client details
Fixed test data 2 in the terms and conditions of the quote
you could append the filters and fixed text 2 to keep it dynamic. try:
={IFNA(FILTER({'Car Parks'!A:AC;'Chapter 8'!A:AC;Production!A:AC;CSAS!A:AC},{'Car Parks'!A:A;'Chapter 8'!A:A;Production!A:A;CSAS!A:A}<>""));"TERMS AND CONDITIONS";"Lorem ipsum dolor sit amet. Rem laudantium reiciendis eos error quia aut autem molestiae aut temporibus magnam!"}

CONCATENATE or JOIN multiple columns from VLOOKUP into single string

I have a worksheet with 2 tabs - Customers, Data. All tabs have a list of customers. The list on Data is a subset of all Customers. I need to pull available address information for Customers from Data.
I need the Address1-3 columns in Data to be joined using <br> and placed in the Address column in Customers. The situation seems similar to this other SO thread joining results into a single string, however those values are all vertical in different rows and the difference here is the values are horizontal in different columns.
Not working:
=TEXTJOIN("<br>",1,VLOOKUP(A2,Data!A:D,{2,3,4},FALSE))
=TEXTJOIN("<br>",1,QUERY("Data!A:H","SELECT B,C,D WHERE "&A2&"="&Data!A:A))
=TEXTJOIN("<br>",1,FILTER(Data!A:D,A2))
Google Sheets example ready for copy/fiddle.
Example Data - the names have been changed to protect the innocent
Account
Address1
Address2
Address3
City
State
Zip
Country
Facebook
Lorem
Ipsum
Dolor
Menlo Park
CA
94025
United States
Amazon
Sit
Amet
Consectetur
Seattle
WA
98109
United States
Apple
Adipiscing
Elit
Ut
Cupertino
CA
95014
United States
Microsoft
Ultricies
Velit
Eu
Redmond
WA
98052
United States
Google
Interdum
Bibendum
Proin
Mountain View
CA
94043
United States
Example Customers - the names have been changed to protect the innocent
Account
Address
City
State
Zip
Country
Facebook
Walmart
Amazon
Home Depot
Apple
CVS
Microsoft
BMW
Google
Toyota
...
Expected Output
Account
Address
City
State
Zip
Country
Facebook
Lorem<br>Ipsum<br>Dolor
Menlo Park
CA
94025
United States
Walmart
Amazon
Sit<br>Amet<br>Consectetur
Seattle
WA
98109
United States
Home Depot
Apple
Adipiscing<br>Elit<br>Ut
Cupertino
CA
95014
United States
CVS
Microsoft
Ultricies<br>Velit<br>Eu
Redmond
WA
98052
United States
BMW
Google
Interdum<br>Bibendum<br>Proin
Mountain View
CA
94043
United States
Toyota
Your formula is fine, you just have to wrap it in an ArrayFormula():
=ArrayFormula(IFNA(TEXTJOIN("<br>",1,VLOOKUP(A2,Data!A:H,{2,3,4},FALSE))))
You need to FILTER() then join. Try-
=IFERROR(MAP(A2:A14,LAMBDA(x,JOIN("<br>",FILTER(Data!B2:D,Data!A2:A=x)))),"")
Try this:
=ARRAYFORMULA(JOIN("<br>",QUERY({Data!A1:H6},"SELECT Col2,Col3,Col4 WHERE Col1 = '"&A2&"'",0)))
Edit: Harun24hr has the better answer, this will not autofill down.

How do I get REGEXMATCH to look for one term across a range of cells in Google Sheets?

In Google Sheets I have the following formula:
=IF(REGEXMATCH(B1;"offers");"spring";0)
If the cell B1 contains the text "offers" the output will be "spring", otherwise the output will be "0". This works fine but now I want the formular to look at B1 and C1 and if either of them contains "offers" the output should be "spring".
Example Output with formula in column D:
B
C
D
test offers test
lorem ipsum
spring
lorem ipsum
test offers test
spring
lorem ipsum
lorem ipsum
0
I tried the obvious using
=IF(REGEXMATCH(B1:C1;"offers");"spring";0)
but it gives back a #VALUE!
In the second step I want to use this formula in a nested if function like here:
=IF(REGEXMATCH(B1;"offers");"spring";IF(REGEXMATCH(B1;"shop");"summer";0))
The solution seems to be:
=if(and(arrayformula(regexmatch(B1:C1; "(^| )offers( |$)"))); "spring"; "O")
As modified from user6655984's answer in this post. Note I altered the regex to ensure the pattern you are looking to match is preceded by the start of the line or a space, and is proceeded by a space or the end of the line which ensures it does not fall in the middle of a larger string and handles being at the start or end of the main string.
use:
=IF(REGEXMATCH(B1&C1; "offers"); "spring"; 0)
arrayformula:
=INDEX(IF(REGEXMATCH(B1:B&C1:C; "offers"); "spring"; 0))

Filter rows based on field text in Google Sheets

In Google Sheets, I'm trying to get the sum of all values in column B for which column A equals to 'Lorem'. The result should be 15.
A B
1. Lorem 5
2. Lorem 5
3. Ipsum 100
4. Lorem 5
Tried the following formule, but get the error: Formula parse error.
=SUM(FILTER(B1:B4,A1:A4='Lorem'))
Here is the Google Sheet for reference.
Use double quotes around the string.
=SUM(FILTER(B1:B4,A1:A4="Lorem"))
Alternative ways would be..
=SUMIF(A1:A4, "Lorem", B1:B4)
or
=SUMPRODUCT(A1:A4="Lorem", B1:B4)

Google spreadsheets: if cell contains one of a list of predefined values

I have a column in my spreadsheet that holds cells with strings of text like:
Lorem ipsum blah blah category1
Lorem ipsum blah blah category2
I want to have a second column that will hold values dependent on whether the string contains category1, category2, etc. I can do this with something like:
=arrayformula(if(H32:H="","",(iferror(if(search("category1",H32:H),"The First Category"),iferror(if(search("category2",H32:H),"The Second Category"))))))
However, the list of categories itself is dynamic, so rather than hard code them into the formula, I would like to retrieve them from elsewhere in the spreadsheet, ie:
| Category1 | "The First Category" |
| Category2 | "The Second Category" | // I want to be able to add to this list and have the formula retrieve the values.
Does anyone have any idea how I could go about this?
EDIT: Please see sample sheet here. As you can see, the arrayforumula in A2 looks at the first 3 key values in E2 - E4, and gets the corresponding replacement values. However, I want to be able to add to the list of key/replacements without having to go and manually change the formula in A2 each time.
This worked for me:
=VLOOKUP(REGEXEXTRACT(C2,JOIN("|",INDIRECT("E2:E"&COUNTA(E:E)))),E:F,2,FALSE)
So to explain a little, the portion you see with the join function and indirect, is basically a dynamic regex, that will extend itself automatically (using the counta function) when you add new category types to your source list
So it does the Vlookup, to pull the value that matches a dynamic regex, and returns the corresponding index, "2"

Resources