Two conditions in Google Sheets Function - if-statement

I have a question on using two functions with an if statement in Google Sheets as one complete function. Both variables have to be true, otherwise it returns false. I need one function to check the date 20 months back from today. If said cell is less than today's date 20 months back it's true, naturally. However, for the complete function to return true it also searches for another text value in another cell and has to be an exact match. Both conditions have to be true (the date and the exact match) for the function to be true. So if the date in the cell is less than today's date 20 months back and the text value in the other cell is an exact match, function is true.
Problem is that it seems like the date function does not seem to apply.
=IF(D2<DATE(YEAR(TODAY()),MONTH(TODAY())-20,DAY(TODAY())),AND(REGEXMATCH(M2,"text")),TRUE,FALSE)

You current formula is not set up correctly (nor logically). Given only what you've shown here, this should work:
=IF(AND( D2<DATE(YEAR(TODAY()),MONTH(TODAY())-20,DAY(TODAY())), REGEXMATCH(M2,"text") ),TRUE,FALSE)
Notice that the AND( ) contains both conditions here, whereas your original formula had it only around the second condition.
However, a shorter version of this would be as follows:
=AND( D2<DATE(YEAR(TODAY()),MONTH(TODAY())-20,DAY(TODAY())), REGEXMATCH(M2,"text") )
... since the result of a properly functioning AND( ) is always TRUE or FALSE anyway.

It looks like you're supplying 4 arguments to the IF statement:
=IF(DATECHECK,AND(TEXTCHECK),TRUE,FALSE)
The IF statement expects 3 arguments instead. 1) the condition, 2) the value if true, and 3) the value if false. You can combine your two conditions using an AND statement like this:
AND(DATECHECK,TEXTCHECK)
The final formula would then be:
=IF(AND(D2<DATE(YEAR(TODAY()),MONTH(TODAY())-20,DAY(TODAY())), REGEXMATCH(M2,"text")),TRUE,FALSE)

Related

Google sheets IF stops working correctly when wrapped in ARRAYFORMULA

I want this formula to calculate a date based on input from two other dates. I first wrote it for a single cell and it gives the expected results but when I try to use ARRAYFORMULA it returns the wrong results.
I first use two if statements specifycing what should happen if either one of the inputs is missing. Then the final if statement calculates the date if both are present based on two conditions. This seems to work perfectly if I write the formula for one cell and drag it down.
=IF( (LEN(G19)=0);(U19+456);(IF((LEN(U19)=0) ;(G19);(IF((AND((G19<(U19+456));(G19>(U19+273)) ));(G19);(U19+456))))))
However, when I want to use arrayformula to apply it to the entire column, it always returns the value_if_false if neither cell is empty, regardless of whether the conditions in the if statement are actually met or not. I am specifically talking about the last part of the formula that calculates the date if both input values are present, it always returns the result of U19:U+456 even when the result should be G19:G. Here is how I tried to write the ARRAYFORMULA:
={"Date deadline";ARRAYFORMULA(IF((LEN(G19:G400)=0);(U19:U400+456);(IF((LEN(U19:U400)=0);
(G19:G400);(IF((AND((G19:G400<(U19:U400+456));(G19:G400>(U19:U400+273)) ));(G19:G400);(U19:U400+456)))))))}
I am a complete beginner who only learned to write formulas two weeks ago, so any help or tips would be greatly appreciated!
AND and OR are not compatible with ARRAYFORMULA
Replace them by * or +
Try
={"Date deadline";ARRAYFORMULA(
IF((LEN(G19:G400)=0),(U19:U400+456),
(IF((LEN(U19:U400)=0), (G19:G400),
(IF((((G19:G400<(U19:U400+456))*(G19:G400>(U19:U400+273)) )),(G19:G400),
(U19:U400+456)))
))
)
)}
Keep in mind you cannot use AND, OR operators in an arrayformula, so you must find an alternative method such as multiplying the values together and checking them for 0 or 1 (true*true=1)
I am gathering based on your formula's and work that you want to have the following:
If G19 is blank show U19 + 456
If U19 is blank show G19
If G19 is less than U19 + 456 but greater than U19 + 273 show G19
Otherwise show U19 + 456
I'm not too sure what you want to happen when both columns G and U are empty. Based on your current formula you are returning an empty cell + 456... but with this formula it returns an empty cell rather than Column U + 456
Formula
={"Date deadline";ARRAYFORMULA(TO_DATE(ARRAYFORMULA(IFS((($G19:$G400="")*($U19:$U400=""))>0,"",$G19:$G400="",$U19:$U400+456,$U19:$U400="",$G19:$G400,(($G19:$G400<$U19:$U400+456)*($G19:$G400>$U19:$U400+273))>0,$G19:$G400,TRUE,$U19:$U400+456))))}

IF AND Formula with IS NOT NULL in Excel

I am using Excel 2010 and currently trying to get a formula for my data using a Nested If And, but unable of the correct formula.
Here is some sample data to elaborate on my point:
(A1) Received Date (B1) DueDate
(A2) 7/1/2016 (B2) 7/8/2016
(A3) 7/1/2016 (B3) 6/29/2016
(A4) 7/1/2016 (B4) NULL
Basically, I want to create a formula that satisfies the following conditions. If Received Date < DueDate AND DueDate IS NOT NULL...then "YES", else "NO". So in this sample code above, only the first record should return "YES" and the other two should return "NO."
How do I do about a formula doing this?
I don't know how to do the second condition, the IS NOT NULL part. I put the cell numbers in parenthesis to simulate the table. (Hope that helps.)
Excel does not have a function to test for null. You can use IsBlank() to check for a blank cell or you can use IsNumber() to check for a numeric value. So, in your case something like
=if(and(isnumber(B2),A2<B2),"something","else")
Edit: If you want to check for the text "Null", then
=if(and(B2<>"Null",A2<B2),"something","else")
= is the "equals" comparison operator. "Not equals" is done with the <> comparison operator. Or you could do Not(B2="Null") but that's a bit too curly.
Another edit: FWIW, the first formula should still work, regardless of the cell containing text or being blank. As soon as the cell contains a date (which is a numeric value), the condition will be TRUE. So you can use that formula as well.
=IF(AND(B2<>"NULL",A2<B2),"YES","NO")

Crystal Reports Else If statement

I can't figure out why this if statement won't work.
I have a DateTime field DATEFROM and a String parameter (it HAS to be String) periodEnd.
I would like to calculate percentages depending if these two dates have 1, 2, 3 or more years difference.
When I use this formula I get either "100%" or "-" and never the other two options. It's like CR calculates the first IF and if it's true then: "100%" but if it's false, it never checks for the rest of the Else Ifs and goes dirreclty to Else
StringVar percentage:="";
If (cDate({?periodEnd})-{TABLE.DATEFROM})<=1 Then
percentage:="100%"
Else If (cDate({?periodEnd})-{TABLE.DATEFROM})<=2 Then
percentage:="66%"
Else If (cDate({?periodEnd})-{TABLE.DATEFROM})<=3 Then
percentage:="33%"
Else
percentage:="-"
Any idea?
a) I assume you already made sure your periodend format matches with what cdate interprets?
If you just subtract them, Crystal by default returns the number of days between.
Two ways you can do year:
datediff("yyyy",cDate({?periodEnd},{TABLE.DATEFROM})
or
year(cDate({?periodEnd})-year({TABLE.DATEFROM})
b) You've also no doubt accounted for when your {TABLE.DATEFROM} is greater than cDate({?periodEnd} and you have a negative result?
Not sure if the following is the behavior you would want, but I'm throwing it in for your information
ABS(datediff("yyyy",cDate({?periodEnd},{TABLE.DATEFROM}))
**make sure you check the help file for the datediff codes ("yyyy" etc) as they are not quite instinctive and can trip you up when you think you're using the obvious one

IF statement in Excel with date1 and endtime variables

I have got an excel which has an formula and I am not able to understand how its working.
Here is the formula
=IF(C6=date1,0,IF(D6-endtime<=0,0,IF(D6-endtime>0,(D6-endtime)*1440)))
Can someone spends few minutes to post an explanation, how it works
Thanks,
Try looking at it like this:
=IF(C6=date1,
0,
IF(D6-endtime<=0,
0,
IF(D6-endtime>0,
(D6-endtime)*1440
#no "else statement" here!
)
)
)
So the first thing checked is if the cell C6 equals date1, which I think is a named range. If they are equal, then the whole equation resolves to the next line, 0
If they are not equal then D6-endtime is evaluated, if it is less than or equal to zero, then the equation resolves to zero.
If D6-endtime is greater than 0, then the next test is true and the whole equation resolves to (D6-endtime)*1440. There is no else in this last test because equation assumes D6-endtime will always be numeric.
Here's how I understand IF statements work in excel
=if(logical test,value if test true,value if test false)
For logical test, you have to use something that resolves to TRUE or FALSE, or you can specify TRUE or FALSE directly(but then you don't need an IF statement)
value if test true, if the test resolves to TRUE(like 1=1), then the cell will display this value, and supply this value to other functions
value if test false, if the test resolves to FALSE(like 1=0), then the cell will display this value, and supply this value to other functions.
You can omit value if TRUE/FALSE, and excel will return TRUE or FALSE after evaluation of the statement.

Finding the last non-empty cell across multiple sheets

I want to write a formula that looks at the value of a specific cell across other sheets and returns the last non-empty value.
For example, if:
Sheet2.B5 = 3
Sheet3.B5 = ""
Sheet4.B5 = 6
Sheet5.B5 = 4
Sheet6.B5 = ""
Then I would want the formula to return 4.
Any help is much appreciated, I've been working on this for a while without success.
This returns the desired result, although it's not sophisticated or automatic in any way:
=if(not(isblank(Sheet6.B5)), Sheet6.B5,
if(not(isblank(Sheet5.B5)), Sheet5.B5,
if(not(isblank(Sheet4.B5)), Sheet4.B5,
if(not(isblank(Sheet3.B5)), Sheet3.B5,
if(not(isblank(Sheet2.B5)), Sheet2.B5,
"")))))
It starts looking at the last Sheet6.B5: if it's not blank, that's the value to take, otherwise look at Sheet5.B5: if it's not blank... and so on. Finally if they are all blank, return blank.