Comments on: Using logical functions in Excel: AND, OR, XOR and NOT

Last week we tapped into the insight of Excel logical operators that are used to compare data in different cells. Today, you will see how to extend the use of logical operators and construct more elaborate logical tests to perform more complex calculations and more powerful data analysis. Excel logical functions such as AND, OR, XOR and NOT will help you in doing this. Continue reading

Comments page 4. Total comments: 567

  1. is the following

    IF (10.26-(C1+R1)0.49; 1, 0)

    My question is:

  2. Let's see if I can explain my problem:
    I have a row of an approx 200 empty cells and I want to assign a number (1) at a defined interval (10.26). The formula I'm working on is the following

    IF (10.26-(C1+R1)0.49; 1, 0)

    My question is: there is a way to nest the two functions and make the SUM work dinamically maybe using a different formula altogether?

    Thanks in advance for taking the time to answer my question.

    1. Hello!
      I’m sorry but your task is not entirely clear to me. Could you please describe it in more detail? Thank you!

      1. The msg was trunkated, here it is again
        Let's see if I can explain my problem:
        I have a row of an approx 200 empty cells and I want to assign a number (1) at a defined interval (10.26)
        The formula I'm working on is the following
        IF (10.26-(C1+R1)0.49; 1, 0)
        My question is: there is a way to nest the two functions and make the SUM work dinamically
        maybe using a different formula altogether?
        Thanks in advance for taking the time to answer my question.

  3. how to calculate for 3 of more arguments?
    below is what I mean:
    Grater or equator 100 =excellent
    Between 50 to 90 =very good
    Less than 40 =fail

    1. Hello!
      The formula below will do the trick for you:

      =IF(A1>=100,"excellent",IF(AND(A1>=50,A1<=90),"very good",IF(A1<40,"fail","")))

      I hope this will help.

  4. I have a more complicated logic function than I can work out. I am assessing building capacity and need to identify a building as 'under capacity' (where room capacity is greater than customer numbers), 'extend hours' (where room capacity is less than customer numbers, but where opening hours are equal to or less than 37.5 hours per week) and 'exceeds capacity' (where room capacity is less than customer numbers, but where opening hours are more than 37.5 hours per week OR where the room capacity is identified as 'zero').

    Please help!

    1. Hello Phil!
      If I understand your task correctly, the following formula should work for you:

      =IF(F1 > F2,"under capacity",IF(F3 < 37.5,"extend hours","zero"))

      where
      F1 - room capacity
      F2 - customer numbers
      F3 - opening hours

  5. Need result as below
    1. If value is > or = 0 then result will be= 80,
    2. If value is <0 to -03 then result will be= 70,
    3. if value is -04 to -07 then result will be= 60
    4. if value is -08 to -15 then result will be= 50

    -Advance thanks

    1. Hello!
      There is no need to use the AND or OR function.
      The formula below will do the trick for you:

      =IF(A1>=0,80,IF(A1>-3,70, IF(A1>-7,60,IF(A1>-15,50,"" ) )) )

      1. Hi I have a similar problem to the one above but I need to make the values specific to individual suppliers
        e.g IF "ACE" is the supplier but I need to specify tariffs for different pipe sizes eg <20, 20-25,40-45,50-63 etc but different suppliers have different names, size ranges and tariffs how can I write this so the correct tariff is selected for each pipe size in each supplier?
        I would greatly appreciate some help with this!
        Thanks in advance

        1. Hello!
          You need to search by two criteria - the name of the supplier and the size of the pipe. Perhaps this article on searching by several criteria using the INDEX + MATCH functions will be useful
          I hope this will help, otherwise please do not hesitate to contact me anytime.

          1. Fantastic, thank you very much. I will look at the article just now. I may be back for more help....
            Kind regards
            Leigh

  6. Hy! Help me please with the following two tasks. Thank you very much in advance!
    1. Having a personal ID number starting 1 or 5 for boys and 2 or 6 for girls, I must write in a column if that person is a girl or a boy. I tried to combine IF and XOR functions but didn`t work for me.
    2. how to transform the numbers like 6,05 into text in this format: (six,05%)

    Congratulations for what you are doing in helping us!

    1. Hello!
      If I got you right, the formula below will help you with your task:

      =CHOOSE(--LEFT(A1,1),"Boy","Girl", "","","Boy","Girl","","","")

      and

      =CHOOSE(--LEFT(A6,1),"one","two","three", "four","five","six","seven", "eight","nine")& MID(A6,SEARCH(",",A6,1),10)&"%"

      I hope this will help

  7. Help. I have a working formula like this, OR(D9="X", E9="55",D9="B"), in the data validation. How can I modify this in a way that when D9="B" then only "55" value is allowed in E9? meanwhile allowing any values on E9 when D9="X"?
    Thank you in advance.

    1. Hello Miles!
      If I understand your task correctly, the following formula should work for you:

      OR(AND(E9="55",D9="B"),D9="X")

      I hope it’ll be helpful.

  8. I want in excel sheet, 5+6+7*+8= 26. (*) it's cricket talk Batsman Not Out.
    How I put in excel sheet.

    1. Hello Sanjoy!
      I’m sorry but your task is not entirely clear to me. Could you please describe it in more detail? What is "cricket talk Batsman Not Out"?? Also write what exactly you want to receive.I will try to help you.

  9. CURR. T. INV. VALUE VALUE CONVERTED IN AED
    USD 11,545.00 (CURRENCY(1)=VALUE IN AED) * INV VALUE = TOTAL CONVERSION VALUE
    EUR 1,199.00
    KWD 2,000.00
    AED 5,000.00
    QAT 12,000.00
    GBP 1,500.00

    USD 3.674
    EUR 3.99
    KWD 11.9
    AED 1
    QAT 1.01
    GBP 4.59

    Can anyone help me with the formula for the above.
    If I enter the currency whether it's Eur or USD the amount will be converted automatically and whatever the conversion is, it will be multiplied by Column 2 (Total Value) and the total conversion will be on column 3.

    Appreciate you help.

    1. Hello Jane!
      To show the rate for a necessary currency in cell C2, you can use this formula:

      =VLOOKUP(A2,$A$10:$B$15,2,0)

      $A$10:$B$15 is your table with the currency rate, A2 is a cell where the currency is specified (USD in your case).
      Please read more about the VLOOKUP function here.
      If you have any additional questions, I will be happy to answer them.

  10. =IF(AND(E3<6,OR(TIME(11,45,0)<F3<TIME(12,0,0),TIME(18,45,0)<F3<TIME(19,30,0))),"early bird", "")

    write a logical function to find out whether a customer is an early bird. (refer to the 'Early Bird' criteria stated above) In your function, you will have to reference Column E values (day of week) and Column F (time of order) to determine whether customers are early birds. Think about how you will reference the early bird criteria.
    E3= weekday number (1-7)
    f3 time 7:12pm
    Early Bird criteria - Customers who want to avail of an Early Bird discount must place their orders on weekdays between 11:45 a.m. - 12:00 p.m. (for lunch) or 6:45 p.m. - 7:30 p.m. (for dinner).

    can somebody help,

    1. Hello Neha!
      If I understand your task correctly, the following formulas should work for you:

      =IF(AND(E3 < 6,OR(AND(TIME(11,45,0) < F3, F3 < TIME(12,0,0)), AND(TIME(18,45,0) < F3,F3 < TIME(19,30,0)))), "early bird", "")

      Hope you’ll find this information helpful.

  11. thanks this note are very helpful to me as a student

  12. Does RIGHT,LEN,FALSE belong to the logical category

    1. Hi!

      FALSE is categorized under Logical functions; RIGHT and LEN belong to the category of Text functions.

  13. I need help please, i need to a formula about this problem, from jan. 26,2019 to feb. 25, 2019 there are four fridays and 27 working days. The thing i need is on calculating working days minus the working hours for the whole month, see below example
    BG5 BH5 BI5
    Total Working Hrs Total Regular Hrs Total Overtime Hrs
    is from jan26 to feb25 is only 260 hrs is what i also need formula
    and the january month has 31 therefore the total days until february 25 is also 31 days but i need only 26 working days and 4 days fridays. I tried the formula for total overtime as this:=IF(BG5=>BH5,BG5-BH5,0) it only applies when there is only 30 days a month and 4 fridays but does not gave me when there are 5 fridays in a month and also if there is 31th day of the month.
    Any help is Greatly appreciated!

  14. If cell B2 = 43830 (which is December 31, 2019 and assuming that cell B2 does say December 31, 2019) and if (-5 + 2 +7)>0 which is also true, how do I write this to make it work in an IF/AND statement?

    Any help is Greatly appreciated!

    1. =if(and(b2=date(2019,12,31),(-5+2+7)>0),"value if true","value if false")

  15. This article was extremely well-made and useful. Thanks! One question tho, when using a formula with the same format as =OR($C1"", $D2"") , could I instead do =OR(C1:C2"") ?

  16. Hi all,

    I need assistance with the following conditions for a sales model.

    The user wants to sell widgets and they do not want be charged for the 1st 5000 sales. They will then be billed $20 for each widget over 5000 sales. They also only want to pay for a maximum number of widgets (10,000) even if sales exceed this level.
    Any assistance would be greatly appreciated.

  17. Hi Team,

    I need assistance, currently the formula below, works Ok for Text "2019" value in particular column, We converting mmm,dd, yyyy to MM/dd/yyyy. Since the file now contains some "2020" value in text the formula does not convert. I need the Formula to work for Text "2019" or "2020" as well. Please shed some light!!!

    1. =(TEXT(SUBSTITUTE(report!B2,"2019,","2019"),"mm/dd/YYYY"))

  18. HI
    Can you help me
    How to merge the following formula Merged In Excel please suggest
    1.(SUMIF(C1:C8,C5,L1:N7))
    2.IF(I5,"<0",0)

  19. Can you help me write the formula for the following situation: Family Reunion Fees for
    different age groups. I have 2 columns: Column #1 Age; Column #2 Reunion Fee.
    Reunion Fee has these categories:
    If Age is between 13 and 100 then the fee is $125
    If Age is between 4 and 12 then the fee is $85
    If Age is 3, then the fee is $45
    If Age is between 0 and 2 the fee is $0
    I have a data form and will be type in the Age in column #1. I want Excel to select the fees. (I do have a table with the ages and the fees) I don't know how to write a formula that will look up fee for the different ages put that fee in Column #2.
    Information in a Table:
    Ages Reunion Fee
    13 to 100 $125
    4 to 12 $85
    3 $40
    0-2 $0

  20. Hi,
    Can you help me with the formula with 3 conditions to find/count >1hr login & >0 Calls = "Considered for Billing", <1hr login <0 Calls = "Not Considered for Billing", <8hrs login & <0 Calls = "Considered for Billing".
    SL User ID Total No of Calls
    1 1001 8:30:00 80
    2 1002 8:00:00 54
    3 1008 8:00:00 0
    4 1007 3:00:00 34
    5 1006 2:00:00 15
    6 1003 1:00:00 1
    7 1004 1:00:00 0

  21. I had been using lotus 123 a lot.
    In lotus for doing data querry which i filtering data in excel, i could use criterion as logical conditions like age>5#and#age5, age<9)
    does not seem to work

    Any solutions

  22. Please can someone help me solving the following problem.
    In my case
    cell values are as follows:
    D67=0,5
    D68=0,7
    D69=0,9

    When I select the value 0,5 (D67) i want it to move to D21, D22 and D23 into my calculation sheet

    and when I select 0,7 (D68) I want that this value moves to D21, D22 and D23 of my calculation sheet instead and replacing the forgoing value 0,5 ...and so on.

    Is there a solution to this problem?
    Kindest thanks for your help

    Peter

  23. Hi!
    I’m doing some investment cost analysis on a power plant project and could need some help.
    So if I have a plant from 400 MW higher use this formula to estimate cost, if below 400 MW then use this other formula with a coefficient. Do you have any ideas how I could write this?

    BR
    Marco

  24. Hi All,
    I need a formula for the following:

    If the sale date is more than a year from the purchase date then give me half the gain, if not give me the full gain.

    So...

    Purchase Date Sale Date Gain Net gain
    11/03/2018 12/03/2019 5,000 2,500
    13/03/2018 12/03/2019 5,000 5,000

  25. I have seven cells (week days),
    Monday 15
    Tuesday 20
    Wednesday 16
    Thursday 0
    Friday 0
    Saturday 0
    Sunday 0
    and, i update everyday respective day of week. So, I need an "If" formula, that calculate average only for days that their cell is different from 0? (So, if it is Thursday, when i update that cell of Thursday, I want that the average formula to calculate average of days Monday-Thursday only that their value is more than 0, not rest days).

    Thank you :)

  26. Hi
    Could you please help me
    For example
    A1. 100
    B1. 50
    I need 10%,more than B1 not greater than A1 if the value less than 10% I need A1 valvu

  27. JSC_GPA SSC_GPA HSC_GPA Out_Come
    Best Best Best ?
    Best Best Good ?
    Good Good Medium ?
    Best Good Best ?
    Best Best Good ?
    Best Best Best ?

    There are 4 possible categories
    * Best
    * Good
    * Medium
    * Low
    if 2 of then Best then Out_Come Best
    if 2 of then Good then Out_Come Good
    if 2 of then Medium then Out_Come Medium
    if 2 of then Low then Out_Come Low
    Please Help Me....

  28. sir,
    please help how to coding in Ms Excel for the give table in ONE cell.
    =IF(D10-E10=1,"1",IF(D10-E10=1, AND C10=2,"2",IF(C10-D10=2, AND E10=1,"3",IF(C10=1, ANDE10=2,"4",IF(C10-E10=2, AND D10=1,"5",IF(C10-E10-D10=2,"6"))))))
    PLZ CORRECT THE ABOVE FORMULA

  29. Hello,
    Could you please help me why my function does not work:
    =IF(OR(CO2="4 - High Professional",CO2="7 - Versatile Performer",CO2="8 - Future Star",CO2="9 - Star Performer","Top Talent",IF(CO2="0","Not Reviewed","Rest")))

    Thank you for your suggestions

  30. one day i'll understand

    1. same bro same ajwndoiwejfie

  31. Hey so im trying to pick up numbers in negative in the tabel

    Cell1 Cell2 (this is in a tabel)
    A 2
    D -1
    A -3
    A 1
    D 3
    E 2
    A -1

    If i want to only pick up the sum of all "A" that is negative numbers ignoring the positives and the other letters, anyone know how to do that? (the result should be -4 in this case)

    1. I have tried this one but dosent work.
      =SUM.IF(Cell1,"A",IF(Cell2<0,Cell2;0))

  32. I am applying double OR function inside IF but getting results in both digits as well as words
    Please suggest me

  33. rollno name eng hindi sci maths Total
    1 ram 56 100 57 76 289
    2 sham 76 68 14 20 178
    3 sita 24 91 66 59 240
    4 gita 99 83 13 77 272
    5 radha 60 63 40 40 203
    6 mohan 32 77 65 52 226

    Enter roll or name
    ram /1 56 100 57 76 289

    if enter roll name or name then all sub marks dispaly is it possible using vlookup??

  34. Hi, i want to know the formula in Excel if i need to identify the negative figures and make it zero automatically then what is the formula.

  35. I have an excel sheet with many statements giving results as "True" or "False"

    1) Now I need to introduce another column which will say if Cell A1, Cell A2, Cell A3 and Cell A4 are "True" say "Yes" if not say "No"

    2) I also need another formula which says if Cell A1 and Cell A4 are "True" and Cell A2 or Cell A3 are "True" say "Yes" if not say "No"

    Can Someone please help me

  36. Hi!
    I have 2 worksheets containing an identical layout - one is data ran last week called ‘old”containing 6000 rows of customer data and then data ran this week ‘new’ containing 7000 rows of data. Both have one header row. I need to find any changes occurred on each customer record - column A contains a unique ID for each customer and column P is the data range I need to look for changes in). NB; the data will be held on different numbered rows . So to match and highlight unique id’s/customers from column A on the old sheet to column A on the new sheet ( I can do this by using conditional formatting =COUNTIF(old!$A;$A,A2)=1 with a range of $A$:$A$9999. Then I format fill in green to highlight but then of these matched green cases I need to look in column P for any changes to compare old and new values and it’s this part of the formula I need help with.... thanks in advance for any help anyone can offer.

  37. I've been trying to figure this out for two days using various resources and I'm stuck. I feel like the solution is easy and I'm just overthinking it at this point.

    Let's say I have a table in Excel with headers and many rows of varying text and numbers, with some cells containing both (random ID numbers generated by an outside source). The table and headers have names for use in other formulas (no trouble there).

    Col_With_Hdr_1
    A Specific Name In This Cell
    Another Specific Name In This Cell

    Col_With_Hdr_8
    (123abc678ruw9257xyz)
    this is literally a blank cell
    (2756imv47zqp115mv2)
    this is literally a blank cell

    Col_With_Hdr_11
    formula result displayed as text goes here
    formula result displayed as text goes here
    this would be blank if formula result is 0 or No

    I can't figure out how to write a formula that shows

    IF Col_With_Hdr_1="A Specific Name in This Cell" then put specific text in Col_With_Hdr_11

    OR

    IF Col_With_Hdr_8 IS NOT BLANK then put same specific text in Col_With_Hdr_11

    I hope this makes sense, and I appreciate any ideas anyone may have. Thank you!

  38. Hi, I need to calculate the tax for the incomes. If the income is 5000 that is tax free. If the income is greater than 5000 and less than 12500 then, it is 12500-5000 and the remaining is taxed 2% and if the income is more than 12500 and less than 100000 then first 5000 is deducted then 12500 is deducted to be taxed 2% and then the remaining is taxed 10% and if the income is more than 100000 then the 87500 is to be taxed at 10% and then the remaining is taxed 20%. Is it possible to bring them in only one function? Thanks for your kind support.

  39. Using excel formulae, find out the following
    1. How many have neither registered nor completed any of the 3 courses?
    2. How many have registered or trained in atleast 2 of the 3 courses?
    3. How many have not been trained in any of the 3 yet?

    R - Registered for training (training not done yet)
    T - Trained
    Blank - Neither

    Name SQL SAS Excel
    Prakash R T
    Rahul R
    Rajiv
    Priya R T
    Amit T

  40. I wrote the following code. The code provides partial result correctly, but not all! I don't know what is the wrong with my code? =IF((Distance/C4)<1, E_saved,(IF((Distance/C4)<2, (E_saved-(1.8*((Distance/C4)-1))),(IF((Distance/C4)<4, (E_saved-(1.8+(3.35*((Distance/C4)-2)))),(IF((Distance/C4)<11,(E_saved-(1.8 +(3.35*2)+(2.375*(Distance/C4)-4))),0)))))))

  41. I need formular for 2 criterias,

    Increase base salary offer (X)
    if GPA is
    >3.5 by 2000
    >3.0 by 1000
    >2.5 by 500

    and additional bonus
    if experiential activity
    >4.5 $3,500
    >4.0 $3,000
    >3.0 $2,500

  42. SL P A = Error
    - P - = P
    SL P - = SL
    - P A = A

  43. hi,
    What formula could i use if i don't want a number to go over 7.5...If a number is lower, is displays the actual number but if it's higher it shows only 7.5
    THank you,

    1. HI..

      =IF(H19<7.5,H19,7.5)

  44. How to write a formula for this
    10 - 64 Reading below grade level
    65- 81 On Level
    82 - 100 Reading above grade level

    Thank you so much

    1. Hello, Arcita,
      Please try the following formula:

      =IF(A1<=64, "Reading below grade level", IF(A1<=81, "On Level", IF(A1<=100, "Reading above grade level")))

      You can learn more about Excel Nested IF in Excel in this article on our blog.

      Hope you'll find this information helpful.

  45. Hi all
    How can i insert any function in the criteria of countif
    For example i have a marks sheet i want to count that how many student get 80% or more then 80% marks in examination
    One way is i have to calculate the 80% and write in the criteria
    What is another way??

  46. I have A2=28, B2=45 to get a smaller value i applied the formula =IF(A2>B2,A2-B2,A2). So i got an answer has 28.

    My question is if i change a value in A2=50 now i should get a value has B2 in C2 cell.

    So i have entered has =IF(A2>B2,A2-B2,A2)*OR(IF(A2<B2,B2,B2))

    Still it is not working, can someone assist me how to put a formula with a proper condition?

  47. You have eliminated my sleepless night for weeks now.
    Thanks

  48. COMPLETE SUCCESS

    I used the following formulas to test and see if the date format translates to a number, which it did
    =LEFT(MONTH(D13),2)

    Then expanded it to check for output for two months - it worked
    =IF(LEFT(MONTH(D11),2)="5","May",IF(LEFT(MONTH(D11),2)="6","Jun",""))

    FORMULA WHICH WORKED (expanded it to 12 months, put Jan as 01)
    ------------------------------
    =IF(LEFT(MONTH(D10),2)="01","Jan",IF(LEFT(MONTH(D10),2)="2","Feb",IF(LEFT(MONTH(D10),2)="3","Mar",IF(LEFT(MONTH(D10),2)="4","Apr",IF(LEFT(MONTH(D10),2)="5","May",IF(LEFT(MONTH(D10),2)="6","Jun",IF(LEFT(MONTH(D10),2)="7","Jul",IF(LEFT(MONTH(D10),2)="8","Aug",IF(LEFT(MONTH(D10),2)="9","Sep",IF(LEFT(MONTH(D10),2)="10","Oct",IF(LEFT(MONTH(D10),2)="11","Nov",IF(LEFT(MONTH(D10),2)="12","Dec",""))))))))))))

    1. Used the LEFT(MONTH(CELL_REF),2) to verify the translation of the date to number, THEN expanded it to the following, it worked.

      =IF(LEFT(MONTH(D10),2)="01","Jan",IF(LEFT(MONTH(D10),2)="2","Feb",IF(LEFT(MONTH(D10),2)="3","Mar",IF(LEFT(MONTH(D10),2)="4","Apr",IF(LEFT(MONTH(D10),2)="5","May",IF(LEFT(MONTH(D10),2)="6","Jun",IF(LEFT(MONTH(D10),2)="7","Jul",IF(LEFT(MONTH(D10),2)="8","Aug",IF(LEFT(MONTH(D10),2)="9","Sep",IF(LEFT(MONTH(D10),2)="10","Oct",IF(LEFT(MONTH(D10),2)="11","Nov",IF(LEFT(MONTH(D10),2)="12","Dec",""))))))))))))

      1. Sunny:
        Alright! That's a lot of nested IF's but you figured it out. Congratulations on a good use of the MONTH function.
        Thank you for sharing. I'm sure others will benefit from your work.

  49. SUCCESS:
    I was able to achieve and find the conversion of the date format to a number with "=LEFT(MONTH(D13),2)"

    THEN, I expanded the formula to:
    =IF(LEFT(MONTH(D12),2)="1","Jan", IF(LEFT(MONTH(D12),2)="2","Feb", IF(LEFT(MONTH(D12),2)="3","Mar",IF(LEFT(MONTH(D12),2)="4","Apr",IF(LEFT(MONTH(D12),2)="5","May",IF(LEFT(MONTH(D12),2)="6","Jun",IF(LEFT(MONTH(D12),2)="7","Jul",IF(LEFT(MONTH(D12),2)="8","Aug",IF(LEFT(MONTH(D12),2)="9","Sep",IF(LEFT(MONTH(D12),2)="10","Oct",IF(LEFT(MONTH(D12),2)="11","Nov",IF(LEFT(MONTH(D12),2)="12","Dec",""))))))))))))

    BUT
    The blank cells are coming up with "Jan" where it should be a blank "" as in the formula above.
    Any suggestions or input?

  50. I am trying to find a formula where if a LEFT 2 is 01, 02, 03 etc (for date 01/01/18 style), and it enters:
    - Jan if it is 01 of a 01/01/18 date format
    - Feb if it is 02 of a 02/01/18 format
    I have tried the following, but it did not work:
    =IF(LEFT(D21,2)="01","Jan",IF(LEFT(D21,2)="02","Feb",""))
    Kindly assist.
    Sunny

Post a comment



Thank you for your comment!
When posting a question, please be very clear and concise. This will help us provide a quick and relevant solution to
your query. We cannot guarantee that we will answer every question, but we'll do our best :)