fbpx
Search
Close this search box.

Writing “Either Or” formula in Excel [Formula Howtos]

Share

Facebook
Twitter
LinkedIn

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:

Either Or formula in Excel - howto?

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.

Wikipedia defines XOR as,

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?

Facebook
Twitter
LinkedIn

Share this tip with your colleagues

Excel and Power BI tips - Chandoo.org Newsletter

Get FREE Excel + Power BI Tips

Simple, fun and useful emails, once per week.

Learn & be awesome.

Welcome to Chandoo.org

Thank you so much for visiting. My aim is to make you awesome in Excel & Power BI. I do this by sharing videos, tips, examples and downloads on this website. There are more than 1,000 pages with all things Excel, Power BI, Dashboards & VBA here. Go ahead and spend few minutes to be AWESOME.

Read my storyFREE Excel tips book

Excel School made me great at work.
5/5

– Brenda

Excel formula list - 100+ examples and howto guide for you

From simple to complex, there is a formula for every occasion. Check out the list now.

Calendars, invoices, trackers and much more. All free, fun and fantastic.

Advanced Pivot Table tricks

Power Query, Data model, DAX, Filters, Slicers, Conditional formats and beautiful charts. It's all here.

Still on fence about Power BI? In this getting started guide, learn what is Power BI, how to get it and how to create your first report from scratch.

Weighted Average in Excel with Percentage Weights

Weighted Average in Excel [Formulas]

Learn how to calculate weighted averages in excel using formulas. In this article we will learn what a weighted average is and how to Excel’s SUMPRODUCT formula to calculate weighted average / weighted mean.

What is weighted average?

Wikipedia defines weighted average as, “The weighted mean is similar to an arithmetic mean …, where instead of each of the data points contributing equally to the final average, some data points contribute more than others.”

Calculating weighted averages in excel is not straight forward as there is no built-in formula. But we can use SUMPRODUCT formula to easily calculate them. Read on to find out how.

18 Responses to “Writing “Either Or” formula in Excel [Formula Howtos]”

  1. Pedro Roenick says:

    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.

  2. Patricia says:

    Been there... done that 🙂
    Create a long complex IF incorporating an AND or OR and then after re-looking at it, change it to incorporate a and suddenly the function is more legible, more understandable and more elegant. The poor is often overlooked.

  3. Patricia says:

    sorry... my NOT EQUAL sign ""s did not display on my comment.

  4. Nerdilicious! says:

    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)

  5. Alex says:

    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

  6. Bets says:

    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 cross-eyed and perhaps, a little insane trying to work this.  Thanks for your help!

     

    • Hui says:

      @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

  7. Adhita says:

    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!

    • Hui... says:

      @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?

  8. N K Bharali says:

    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.

  9. Oceana says:

    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.

  10. kunaljeet says:

    how to calculate HRA as 20% of BASIC or rs. 2500 whichever is less? pls help

    • Chandoo says:

      @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.

  11. Brandon says:

    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.

  12. Edward Brown says:

    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?

Leave a Reply