Basic IF & IF/AND Not Working…

zero269

Active Member
Joined
Jan 16, 2023
Messages
253
Office Version
  1. 365
Platform
  1. Windows
Hello,

I seem to be having some annoying issues with trying to get what I thought was a basic IF/AND formula to work. I even tried just a basic IF statement, and that too, is giving me a hard time.

Basically, I'm checking if a value is both >=1 AND <=4 AND if another cell is a number (date).

Here's my Sample Data trying a few scenarios.

I'm evaluating the data in the Left Table, and the Right Table is running a few basic tests.

The RIGHT column is grabbing the right value only from the Period column.
Excel Formula:
=RIGHT(t_Period[@Period],1)

The 1 Criteria column is supposed to only check if RIGHT is >=1… appears to be working, but it's actually a NO GO when I change the >=1 to >=2 and it returns TRUE for a 1 value.
Excel Formula:
=LET(
Quarter, RIGHT(t_Period[@Period],1),
IF(Quarter >=1,TRUE,FALSE))

2 Criteria is trying the IF/AND; another NO GO.
Excel Formula:
=LET(
Quarter, RIGHT(t_Period[@Period],1),
IF(AND(Quarter >=1,Quarter<=4),TRUE,FALSE))

3 Criteria is where I'm checking if the Start Date is a number (ISNUMBER).
Excel Formula:
=LET(
StartDate, ISNUMBER(t_Period[@Start]),
Quarter, RIGHT(t_Period[@Period],1),
IF(AND(Quarter >=1,Quarter<=4,StartDate),TRUE,FALSE))

Test # is just testing if RIGHT is >2, so why it returns TRUE for that 1 value is beyond me.
Excel Formula:
=IF([@RIGHT]>=2,TRUE,FALSE)

Any help with the 3 Criteria column would be greatly appreciated...

VBA Testing.xlsm
ABCDEFGHI
1PeriodStartRIGHT1 Criteria2 Criteria3 CriteriaExpectedTest #
21.12024-08-161TRUEFALSEFALSETRUETRUE
31.22024-10-252TRUEFALSEFALSETRUETRUE
41.32025-01-173TRUEFALSEFALSETRUETRUE
51.44TRUEFALSEFALSETRUETRUE
61.52024-08-165TRUEFALSEFALSEFALSETRUE
71.62025-06-076TRUEFALSEFALSEFALSETRUE
IF_AND
Cell Formulas
RangeFormula
D2:D7D2=RIGHT(t_Period[@Period],1)
E2:E7E2=LET( Quarter, RIGHT(t_Period[@Period],1), IF(Quarter >=1,TRUE,FALSE))
F2:F7F2=LET( Quarter, RIGHT(t_Period[@Period],1), IF(AND(Quarter >=1,Quarter<=4),TRUE,FALSE))
G2:G7G2=LET( StartDate, ISNUMBER(t_Period[@Start]), Quarter, RIGHT(t_Period[@Period],1), IF(AND(Quarter >=1,Quarter<=4,StartDate),TRUE,FALSE))
I2:I7I2=IF([@RIGHT]>=2,TRUE,FALSE)
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
RIGHT extracts the string as text not as number; adjust your formulas so that they are numbers e.g. like this:

Excel Formula:
--(RIGHT(t_Period[@Period],1))
 
Upvote 0
Solution
RIGHT extracts the string as text not as number; adjust your formulas so that they are numbers e.g. like this:

Excel Formula:
--(RIGHT(t_Period[@Period],1))
Thanks, Hagia,

I made your suggested changes and low and behold, it's working now....
Excel Formula:
=LET(
StartDate, ISNUMBER(t_Period[@Start]),
Quarter, --(RIGHT(t_Period[@Period],1)),
IF(AND(Quarter >=1,Quarter<=4,StartDate),TRUE,FALSE))

Interestingly enough, I continued testing and tried enclosing my numbers with doublequotes ("1"), and they worked as well. That didn't make any sense to me until I read your statement. Now it makes perfect sense. Let's hope I can remember this in the future... ;)

First I just tried AND and got all FALSE's. That's when I changed 1 to "1" and 4 to "4" and they returned the correct results. I think this is my first time hard coding numbers into the formula... maybe.

I prefer your solution over the double quotes... and I read somewhere that the -- replaces VALUE().

Thanks again... this was very helpful! (y)

VBA Testing.xlsm
ABCGHMN
1PeriodStart3 CriteriaExpectedAND3 Again
21.12024-08-16TRUETRUETRUETRUE
31.22024-10-25TRUETRUETRUETRUE
41.32025-01-17TRUETRUETRUETRUE
51.4FALSETRUETRUEFALSE
61.52024-08-16FALSEFALSEFALSEFALSE
71.62025-06-07FALSEFALSEFALSEFALSE
IF_AND
Cell Formulas
RangeFormula
G2:G7G2=LET( StartDate, ISNUMBER(t_Period[@Start]), Quarter, --(RIGHT(t_Period[@Period],1)), IF(AND(Quarter >=1,Quarter<=4,StartDate),TRUE,FALSE))
M2:M7M2=AND([@RIGHT]>="1",[@RIGHT]<="4")
N2:N7N2=LET( StartDate, ISNUMBER(t_Period[@Start]), Quarter, RIGHT(t_Period[@Period],1), IF(AND(Quarter >="1",Quarter<="4",StartDate),TRUE,FALSE))
 
Upvote 0

Forum statistics

Threads
1,224,883
Messages
6,181,551
Members
453,052
Latest member
ezzat

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top