Using IF AND to match three criteria - if-statement

I am trying to use an IF statement to turn a cell Yes if three conditions are met. It's not working for the third condition. Can anyone look at my formula and point me in the right direction? Note: I can't use array formula because there are other rows in the way.
The three conditions are:
The cells in D2:D say User Task
The cells in B2:B match the cells in E2:E of another sheet and either C2:C of that sheet say Yes or Reloaded.
The cells in B2:B of the other sheet match Customer.
=IF(AND(D2:D="User Task",REGEXMATCH(VLOOKUP(B2:B, {
IMPORTRANGE("1YMBUYC6JgQke-2YWs_VZx9zqlmOdhV8WYvhTpTVxBYM", "Sheet1!E2:E"),
IMPORTRANGE("1YMBUYC6JgQke-2YWs_VZx9zqlmOdhV8WYvhTpTVxBYM", "Sheet1!C2:C")}, 2, 0),
"Yes|Reloaded")=TRUE,
IMPORTRANGE("1YMBUYC6JgQke-2YWs_VZx9zqlmOdhV8WYvhTpTVxBYM", "Sheet1!B2:B")="Customer"), "Yes", )
Reference sheets:
Test Sheet 2
Test Sheet 1

it goes like this:
=IF( (con1=true)*(con2=true)*(con3=true), do "yes", otherwise empty)
eg:
=ARRAYFORMULA(IFERROR(IF(($D$2:$D="User Task")*(REGEXMATCH(VLOOKUP($B2:B, {
IMPORTRANGE("1YMBUYC6JgQke-2YWs_VZx9zqlmOdhV8WYvhTpTVxBYM", "Sheet1!E2:E"),
IMPORTRANGE("1YMBUYC6JgQke-2YWs_VZx9zqlmOdhV8WYvhTpTVxBYM", "Sheet1!C2:C")}, 2, 0),
"Yes|Reloaded")=TRUE)*
(IMPORTRANGE("1YMBUYC6JgQke-2YWs_VZx9zqlmOdhV8WYvhTpTVxBYM", "Sheet1!B2:B")="Customer"),
"Yes", )))

Related

Vlookup then return a different row in Google Sheets

I'm struggling to figure out how to get sheets to first look up the location of a key value and then look up which of the sub values it should take. Best would be to include an example, which:
https://docs.google.com/spreadsheets/d/1pL62W7pSImMlTdnU3RMV4VDK3KIuNBT8l3VxClLGTd4/edit?usp=sharing
What I'm hoping to achieve is that the values for item 1, when selected, auto fill in the correct gear builder fields.
Any advice on this is hugely appreciated.
try:
=ARRAYFORMULA(IFNA(VLOOKUP(
IF(F4:F12<>"", VLOOKUP(ROW(A4:A12),
IF(G4:G12<>"", {ROW(A4:A12), G4:G12&"♦"}), 2, 1), )&F4:F12, {
IF(B4:B12<>"", VLOOKUP(ROW(A4:A12),
IF(A4:A12<>"", {ROW(A4:A12), A4:A12&"♦"}), 2, 1), )&B4:B12, C4:C12}, 2, 0)))

How can I apply an Arrayformula for multiple cells on Google Sheets which includes fixed and variable cells?

I want to apply an arrayformula to my worksheet on Google Sheets, which works good when I drop-down the formula to the cells below. But because I have quite much data, I need to use the arrayformula for this formula and I can't find a solution how to apply the variable cell (in this example B11 and C11) to all cells below it.
The screenshot should explain my problem very well.
=COUNTIF((ARRAYFORMULA(IF((ARRAYFORMULA(IF(B11>$B$4:$B$7,IF(C11>$C$4:$C$7,1,0),0)))=1,IF((ARRAYFORMULA(IF($K$4:$K$7>$J$4:$J$7,1,0)))=1,1,0),0))),"1")
Here a link to my file:
https://docs.google.com/spreadsheets/d/1c17IQCujy3cQwDOcbJUpm3iCgJHCbD8QRbK0aQfVtQA/edit?usp=sharing
The output is in the green field
it would be like this:
=ARRAYFORMULA(MMULT(
IF(IF(INDIRECT("B11:B"&COUNTA(B11:B)+10)>TRANSPOSE(B4:B7),
IF(INDIRECT("C11:C"&COUNTA(C11:C)+10)>TRANSPOSE(C4:C7), 1, 0), 0)=1,
IF(IF(TRANSPOSE(K4:K7)>TRANSPOSE(J4:J7), 1, 0)=1, 1, 0), 0), {1; 1; 1; 1}))

Change cell background color based on text in another column

What would the syntax be to conditionally format - if any cell in Column A contains a value that matches any value in Column B then display a blue background?
Looks like this would be done using Conditional Formatting under Format, where this custom formula works.
=OR(A1:A1000="Text Sample 1",A1:A1000="Text Sample 2")
Instead of listing a bunch of values in this formula, is there syntax that can represent values listed in another column (Column B)?
use this custom formula:
=REGEXMATCH(A1, TEXTJOIN("|", 1, B$1:B))
for exact finds use:
=REGEXMATCH(A1, "^"&TEXTJOIN("$|^", 1, B$1:B)&"$")
Custom Formula:
=QUERY(B:B," Select count(B) where B is not null and '"&A1&"' contains B label count(B) ''",0)
Apply to:
A1:A
Queries Column B for every cell in A starting from A1 and outputs count of cells.

Combine two nested IF statements with multiple criteria

I have two columns of data in "Meds" sheet...
MedContinuing AgeAtMedStop
Yes "Blank"
Yes 72.22
No "Blank"
No 72.57
"Blank" 73.85
I am writing a formula in a separate sheet to return 1 or 0 based on the following:
If MedContinuing is "Blank", do nothing
If MedContinuing is "No" and AgeAtMedStop is blank, do nothing
If MedContinuing is "Yes" and AgeAtMedStop is "Blank", return 1. If AgeAtMedStop is a number, return 0.
If MedContinuing is "No" and AgeAtMedStop is a number, return 1. Otherwise, return nothing.
I was able to write two separate functions (see below) for when MedContinuing is "Yes" or when it is "No", but I need to combine both into one formula.
When it's Yes...
=IF(INDEX(Meds!2:2,MATCH("MedContinuing",Meds!$1:$1,0))="","",
IF(INDEX(Meds!2:2,MATCH("MedContinuing",Meds!$1:$1,0))="No","",
IF(AND(INDEX(Meds!2:2,MATCH("MedContinuing",Meds!$1:$1,0))="Yes",INDEX(Meds!2:2,MATCH("AgeAtMedStop",Meds!$1:$1,0))=""),1,0)))
When it's No...
=IF(INDEX(Meds!2:2,MATCH("MedContinuing",Meds!$1:$1,0))="","",
IF(INDEX(Meds!2:2,MATCH("MedContinuing",Meds!$1:$1,0))="Yes","",
IF(AND(INDEX(Meds!2:2,MATCH("MedContinuing",Meds!$1:$1,0))="No",INDEX(Meds!2:2,MATCH("AgeAtMedStop",Meds!$1:$1,0))=""),"",
IF(AND(INDEX(Meds!2:2,MATCH("MedContinuing",Meds!$1:$1,0))="No",INDEX(Meds!2:2,MATCH("AgeAtMedStop",Meds!$1:$1,0))>0),1,0))))
EDIT: Solution
Using Peter K's logic...
=IF(INDEX(Meds!6:6,MATCH("MedContinuing",Meds!$1:$1,0))="","",
IF(AND(INDEX(Meds!6:6,MATCH("MedContinuing",Meds!$1:$1,0))="No",INDEX(Meds!6:6,MATCH("AgeAtMedStop",Meds!$1:$1,0))=""),"",
IF(AND(INDEX(Meds!6:6,MATCH("MedContinuing",Meds!$1:$1,0))="Yes",INDEX(Meds!6:6,MATCH("AgeAtMedStop",Meds!$1:$1,0))=""),1,
IF(AND(INDEX(Meds!6:6,MATCH("MedContinuing",Meds!$1:$1,0))="Yes",INDEX(Meds!6:6,MATCH("AgeAtMedStop",Meds!$1:$1,0))>0),0,
IF(AND(INDEX(Meds!6:6,MATCH("MedContinuing",Meds!$1:$1,0))="No",INDEX(Meds!6:6,MATCH("AgeAtMedStop",Meds!$1:$1,0))>0),1,"")))))
It is not entirely clear from your question why you would use INDEX and MATCH functions for such straightforward problem ?
I suggest to start with the basic nested if function :
=IF(A2="";"";IF(A2="No";IF(B2="";"";1);IF(B2="";1;0)))
You can put this function next to your two columns, and then copy to another worksheet, so the references are taken care of by Excel.
I also assume that your data is clean and correct i.e. only the 3 possible values for MedContinuing ("Yes", "No" or blank) and 2 for AgeAtMedStop (blank or a number) exist in your columns, so no IF test is needed to eliminate other possible values.
You can try this method below
I have created a helper table for the logic you require, it will help to update or extend the logic in future
Formula in cell C2 is
=INDEX($F$2:$G$4,MATCH(A2,$E$2:$E$4,0),IF(B2="Blank",1,IF(ISNUMBER(B2),2,0)))

“Otherwise” argument of my IF-function applies to blank cells, but should ignore them. What can I add to my formula to stop it?

In my IF-function the “otherwise” argument should conduct the subtraction “6 - value”. It works fine for cells containing numbers, but unfortunately also works fine with blank cells. This results in a lot of cells with 6 (6 - 0 = 6) instead of empty cells.
In detail:
I want to import and select data collected in an online questionnaire.
I import my extract of the raw data in sheet “Sample” with the following formula:
=IF(LOOKUP(D$1,'Analysis'!$A$2:$A,'Analysis'!$G$2:$G)="No",FILTER(FILTER(Import!$A$2:$CV,Import!$A$1:$CV$1=D$1),Import!$A$2:$A=0),ARRAYFORMULA(6-FILTER(FILTER(Import!$A$2:$CV,Import!$A$1:$CV$1=D$1),Import!$A$2:$A=0)))
= If the question has not to be reversed (“No”), then import the values as they are, otherwise (if the question has to be reversed, “Yes”) subtract 6 - value.
Sheets in Google Spreadsheets:
“Import”: This sheet contains the raw data. For each person that participated in the study, there is a row with the corresponding answers (that is 1, 2, 3, 4 or 5 according to the rating scale in the questionnaire). Because not every person in the list started or completed the questionnaire, there are blank cells where no answers were registered and blank cells at the end of the sheet.
“Sample”: This sheet should contain an extract of the raw data for further analysis. It’s the sheet where the IF-formula is applied.
“Analysis”: This sheet contains informations concerning the questions, e.g. if the answers of some questions have to be reversed (reversed rating scale: 1 -> 5, 2 -> 4, 3 stays 3 and so on).
Coordinates:
Sheet “Sample”: Cell D$1, E$1, F$1 and so on contain the names of the questions (e.g. question_1).
Sheet “Analysis”: A2 to A contain the names of the questions.
Sheet “Analysis”: G2 to G contain the information if the answers of the questions have to be reversed. If the answers have to be reversed (“Yes”), the raw data needs to be adjusted with “6-” (6-5 = 1, 6-4 = 2, 6-3 = 3 and so on).
Sheet “Import”: A2 to A contains if there are any missing values. Zero means there are no missing values. Only data rows with no missing values should be imported.
Problem:
The formula works fine and displays the answers and reversed answers for the questions of interest. BUT at the end of the sheet “Sample” the columns continue with 6, 6, 6, 6, 6, 6, 6… (only for reversed questions); for not reversed questions the cells after the last valid import are blank.
Attempts to fix it:
I tried different variations of nested if-functions that unfortunately don’t have any effect, e.g.:
=IF(ISBLANK(Import!E2:I8)," ",IF(LOOKUP(D$1,Analysis!$A$2:$A,Analysis!$G$2:$G)="No",FILTER(FILTER(Import!$A$2:$CV,Import!$A$1:$CV$1=D$1),Import!$A$2:$A=0),ARRAYFORMULA(6-FILTER(FILTER(Import!$A$2:$CV,Import!$A$1:$CV$1=D$1),Import!$A$2:$A=0))))
or:
=IF(LOOKUP(D$1,Analysis!$A$2:$A,Analysis!$G$2:$G)="No",FILTER(FILTER(Import!$A$2:$CV,Import!$A$1:$CV$1=D$1),Import!$A$2:$A=0),IF(Import!E2:E=" "," ",ARRAYFORMULA(6-FILTER(FILTER(Import!$A$2:$CV,Import!$A$1:$CV$1=D$1),Import!$A$2:$A=0))))
Alternatively, I could delete the cells with 6, 6, 6,… but that would be very time-consuming for all questionnaires.
Thanks for your help!
The following is the simple pattern
=IF(ISBLANK(A1),,6-A1)
This if A1 is blank, the will return a blank, otherwise, will return the result of 6-A1.
To apply the above to an open-ended reference, nest the above pattern inside FILTER in the following way:
=FILTER(IF(NOT(ISBLANK(A:A)),6-A:A,),LEN(A:A))
Replace A:A by a single column of the imported data, or a formula that returns a column of values.