Writing “Either Or” formula in Excel [Formula Howtos]
We all know the AND, OR & NOT formulas in Excel using which you can perform simple logical operations And, Or & Negate. But what if you are the chief of HR at ACME Company, where they have a strange rule on extra allowance like this:
Now, to calculate the dates in a month that meet this clause, we need an “exclusive OR” formula or what geeks call as “XOR” operation.
The logical operation … exclusive or (symbolized XOR, EOR), … results in a value of true if exactly one of the operands has a value of true. A simple way to state this is “one or the other but not both.”
Now, XOR or exclusive Or is a fairly common logical test, but there is no straight forward formula to test this. Instead we have to use a lengthy combination or AND, OR and NOT formulas to arrive at XOR.
For eg. assuming you want TRUE only when one of the two logical conditions A or B is TRUE,
you have to write,
=OR(AND(NOT(A),B),AND(A,NOT(B)))
[Afterall, that is how XOR operation is defined to begin with]
Now, that seems like an awful formula. May be there is a better formula after all?!? One that is less crazier than the HR clause of ACME Co.
Well, there is.
If you observe closely, XOR is nothing but <> (not equal to sign). So, instead of going nuts writing the lengthy ANDORNOT combination, you can simplify the formula to,
=A<>B
and it gives the same outcome.
So, the formula to find whether a given date (in cell A1) qualifies for bonus allowance,
=IF((WEEKDAY(A1)=6)<>(MOD(DAY(A1),5)=0),"Pay Bonus","Pay Regular")
More about logical formulas in Excel
AND Formula  OR Formula  NOT Formula  51 common excel formulas
Do you XOR in real life?
There have been few occasions when I had to XOR in my worksheets. I found that writing the correct formula can be a bit tricky depending on how crazy the rule is. But almost always a combination of <>, NOT, AND and OR worked for me well.
What about you? Do you write formulas that involve complex IF clauses?
Hello Awesome...
My name is Chandoo. Thanks for dropping by. My mission is to make you awesome in Excel & your work. I live in Wellington, New Zealand. When I am not F9ing my formulas, I cycle, cook or play lego with my kids. Know more about me.
I hope you enjoyed this article. Visit Excel for Beginner or Advanced Excel pages to learn more or join my online video class to master Excel.
Thank you and see you around.
Related articles:

Leave a Reply
« Annual Goals Tracker Sheet [awesome ways to use excel]  Exploring Profit & Loss Reports [Part 4 of 6] » 
18 Responses to “Writing “Either Or” formula in Excel [Formula Howtos]”
What if I have to write a formula for XOR with 3 entries? By that I mean that I need a formula that receives 3 boolean inputs and returns TRUE only when only one of the inputs is also TRUE.
@Pedro.. You can use SUM formula then, like this =SUM(A,B,C)=1 to test whether only of the 3 is true.
Been there... done that 🙂
Create a long complex IF incorporating an AND or OR and then after relooking at it, change it to incorporate a and suddenly the function is more legible, more understandable and more elegant. The poor is often overlooked.
sorry... my NOT EQUAL sign ""s did not display on my comment.
[...] Check for Either Or conditions in Excel [...]
doesn't work in a SUMPRODUCT formula. However, an XOR calculation seems to be easy enough by using '=1'...
Assuming A2:A6={"France";"France";"France";"Other";"Other"} and B2:B6={"France";"Other";"France";"France";"Other"} ...
Not quite OR (counts all occurences of "France"):
=SUMPRODUCT((($A$2:$A$6="France")+($B$2:$B$6="France"))
(=6)
'Proper' OR:
=SUMPRODUCT(((($A$2:$A$6="France")+($B$2:$B$6="France"))>0))
(=4)
XOR:
=SUMPRODUCT(((($A$2:$A$6="France")+($B$2:$B$6="France"))=1))
(=2)
Dear All,
I,ve got some difficulties to make formula in excel chart as below
conditition.
Pls see below table
1 a
2 b
3 c
4 d
5 e
6 f
. .
. .
. .
18 r
I mean, I want if I write "1" in cell A1 then in cell C1 refer to "a".
Do you have an idea for this?
Thanks for your big help
Everyone seems so knowledgable here! I have an issue that I've been stuck on for the past 3 hrs trying to figure out: a formula for this:
I want cell I38 to reflect one of these two values:
If H38 reads "n" or left blank, then perform this function:multiply F38x0.1, then add F38 to that product.
If F38 is not "n" or left blank, But reads "y", then perform this function: I38=F38
Can I even assign two functions like this (an either/or) to one cell? I'm going crosseyed and perhaps, a little insane trying to work this. Thanks for your help!
@Bets
To solve your problem use:
=IF(OR(H38="", H38="n"),1.1,1)*F38
It is quite possible using the If() function to have lots of nested and totally different formulas in one cell which will do different things when the circumstances are right
Hi!
I want to know if it's posssible for me to combine below formulas into one formula using OR.
=IF(P42<="00:45", "A", IF(P42<="01:00", "B", "C"))
OR
=IF(ISNUMBER(SEARCH("", K42, 5)), "C", "A")
thanks!
@Adhita
Yes
But it depends on the order of the if's and or's
The general format is
=If( Or(Condition 1 = Value 1, Condition 2 = Value 2, Condition 3 = Value 3), Value if True, Value if False)
The Or means that it will be true of any of the 3 conditions are met
If you need them all to be True to trigger the If, use And()
=If( And(Condition 1 = Value 1, Condition 2 = Value 2, Condition 3 = Value 3), Value if True, Value if False)
You can nest results as you have done above as well
Can you post a table of what should happen if various combinations of results are met?
Can you help in the following case of profit share  Say
1. Upto a daily profit of 10000, the share is 14%.
2. For profit of 50000 or beyond the share is 20 percent
3. The intervening range (10000 to 50000) is covered by the slope of the two end points.
4. How do I create a formula to cover the ranges below 10000 or above 50000 at 14 percent and 20 percent respectively.
Need help with the following; =if(a3="x",b3, ... but if c3 also =x then add d3. Can someone help with completing this formula? Please.
Therefore b3 =2 d3 =5 Therefore 7 but if no "x" in previous column then number not added. X indicates payments made for next cell.
how to calculate HRA as 20% of BASIC or rs. 2500 whichever is less? pls help
@Kunaljeet... Welcome to Chandoo.org and thanks for posting your question.
Assuming basic salary is in A1, use = MAX(A1 * 20%, 2500)
to calculate HRA.
I am trying to make short interval control charts and I wish to display a start and finish time based on the number of hours that a job takes. I have the formula figured out for a 24 hour schedule, but I need to figure out how to automate the formula for a 20 hours schedule. I want the hours to automatically change to 4:40AM if the cell were to fall between 1:00AM and 4:40AM.
So, my hours column is E, My planned start time is F, and my planned finish time is column H......
The formula I have in column F at the moment is =IF(HOUR(H3+E4)<20,F3+E3/24,INT(H3+1)+MOD(I4,1)) and it appears to be working for a 24 hour schedule as it automatically calculates the time based on the information provided in Column H as the planned finish time.
The formula I have in column H is =F4+E4/24, and this has suited my needs as well based on a 24 hours schedule.
What I need is for both of these columns to automatically change to 4:40AM if the hours would fall between 1AM and 4:40AM
Is this possible, or is there a way to simplify what I am looking at?
A date is number. Every day is equal to 1. Time is also number. 1 hour is equal to 1/24. You can then simply type in the two dates in excel. Let’s make A1 equal to 1:00 and A2 equal to 4:40. You can then simply do an IF formula to say if you time falls between these two cells, make it equal to A2, otherwise make it the same value. I then insert my date to verify in C1, then the formula looks like follows : =IF(AND(C1=A1),A2,C1).
Should you need further help with any excel queries feel free to visit my website at http://www.speccon.co.za we offer online solutions, training and development.
I'm trying to create a formula where if the month equals a particular value (such as 6 for June) then follow the equation =(30  A1)*100 (A1 is the day of the month). If the month does not equal 6 then a fixed value is displayed.
I am trying to create a formula in my budget where the amount I have set aside for my daily allotment for general expenditures decreases based on the day of the month, but only for the month that the budget sheet is written for (I have a separate sheet for each month). The fixed value would be the full amount allocated for the entire month and would be used on future months.
Can you help?