Excel에서 논리 함수를 사용하는 방법 : IF, AND, OR, XOR, NOT

논리 함수는 Excel에서 가장 많이 사용되는 유용한 기능입니다. 다른 셀의 값을 테스트하고 테스트 결과에 따라 작업을 수행 할 수 있습니다. 이를 통해 스프레드 시트의 작업을 자동화 할 수 있습니다.

IF 함수 사용 방법

IF 함수는 Excel의 주요 논리 함수이므로 가장 먼저 이해해야합니다. 이 기사 전체에서 여러 번 나타날 것입니다.

IF 함수의 구조를 살펴본 다음 그 사용 예를 살펴 보겠습니다.

IF 함수는 3 비트 정보를받습니다.

= IF (논리 _ 테스트, [값 _if_true], [값 _if_false])
  • logical_test : 확인할 함수의 조건입니다.
  • value_if_true : 조건이 충족되거나 참인 경우 수행 할 작업입니다.
  • value_if_false : 조건이 충족되지 않거나 false 인 경우 수행 할 작업입니다.

논리 함수와 함께 사용할 비교 연산자

셀 값으로 논리 테스트를 수행 할 때는 비교 연산자에 익숙해야합니다. 아래 표에서 이들에 대한 분석을 볼 수 있습니다.

이제 실제로 작동하는 몇 가지 예를 살펴 보겠습니다.

IF 함수 예 1 : 텍스트 값

이 예에서는 셀이 특정 구문과 같은지 테스트하려고합니다. IF 함수는 대소 문자를 구분하지 않으므로 대문자와 소문자를 고려하지 않습니다.

다음 공식은 C 열에서 B 열에 "완료 됨"텍스트가 포함 된 경우 "아니오"를 표시하고 다른 항목이 포함되어 있으면 "예"를 표시하는 데 사용됩니다.

= IF (B2 = "완료 됨", "아니요", "예")

IF 함수는 대소 문자를 구분하지 않지만 텍스트는 정확히 일치해야합니다.

IF 함수 예 2 : 숫자 값

IF 함수는 숫자 값을 비교하는데도 유용합니다.

아래 수식에서 B2 셀에 75보다 크거나 같은 숫자가 포함되어 있는지 테스트합니다. 포함되어 있으면 "Pass"라는 단어를 표시하고 "Fail"이 아닌 경우에는 단어를 표시합니다.

= IF (B2> = 75, "통과", "실패")

IF 기능은 테스트 결과에 다른 텍스트를 표시하는 것 이상입니다. 또한 다른 계산을 실행하는 데 사용할 수도 있습니다.

이 예에서는 고객이 일정 금액을 지출하면 10 % 할인을 제공하려고합니다. 예를 들어 £ 3,000를 사용합니다.

= IF (B2> = 3000, B2 * 90 %, B2)

수식의 B2 * 90 % 부분은 B2 셀의 값에서 10 %를 뺄 수있는 방법입니다. 이를 수행하는 방법에는 여러 가지가 있습니다.

중요한 것은 value_if_true또는 value_if_false섹션 에서 모든 수식을 사용할 수 있다는 것 입니다. 그리고 다른 셀의 값에 따라 다른 수식을 실행하는 것은 매우 강력한 기술입니다.

IF 함수 예 3 : 날짜 값

이 세 번째 예에서는 IF 함수를 사용하여 기한 목록을 추적합니다. B 열의 날짜가 과거 인 경우 "연체"라는 단어를 표시하려고합니다. 그러나 날짜가 미래인 경우 마감일까지의 일수를 계산하십시오.

아래 수식은 C 열에 사용됩니다. B2 셀의 기한이 오늘 날짜보다 이전인지 확인합니다 (TODAY 함수는 컴퓨터 시계에서 오늘 날짜를 반환합니다).

Original text


= IF (B2

중첩 된 IF 수식이란 무엇입니까?

이전에 중첩 된 IF라는 용어를 들어 보셨을 것입니다. 이것은 우리가 다른 IF 함수 내에 IF 함수를 작성할 수 있음을 의미합니다. 수행 할 작업이 두 개 이상인 경우이 작업을 수행 할 수 있습니다.

하나의 IF 함수는 두 가지 작업 ( value_if_truevalue_if_false) 을 수행 할 수 있습니다. 그러나 value_if_false섹션 에 다른 IF 함수를 포함 (또는 중첩)하면 다른 작업을 수행 할 수 있습니다.

B2 셀의 값이 90보다 크거나 같으면 "Excellent"라는 단어를 표시하고 값이 75보다 크거나 같으면 "Good"을 표시하고 다른 항목이 있으면 "Poor"를 표시하려는이 예를 사용합니다. .

= IF (B2> = 90, "우수", IF (B2> = 75, "좋음", "나쁨"))

이제 하나의 IF 함수가 할 수있는 것 이상으로 공식을 확장했습니다. 필요한 경우 더 많은 IF 함수를 중첩 할 수 있습니다.

수식 끝에있는 두 개의 닫는 대괄호 (각 IF 함수에 대해 하나씩)를 확인하십시오.

이 중첩 된 IF 접근 방식보다 더 깔끔 할 수있는 대체 수식이 있습니다. 매우 유용한 대안 중 하나는 Excel의 SWITCH 기능입니다.

AND 및 OR 논리 함수

AND 및 OR 함수는 수식에서 둘 이상의 비교를 수행하려는 경우에 사용됩니다. IF 함수만으로는 하나의 조건 또는 비교 만 처리 할 수 ​​있습니다.

우리는 고객이 소비하는 양에 따라 10 %의 값을 할인 예를 들어 가지고 몇 년 그들이 고객되었습니다입니다.

자체적으로 AND 및 OR 함수는 TRUE 또는 FALSE 값을 반환합니다.

The AND function returns TRUE only if every condition is met, and otherwise returns FALSE. The OR function returns TRUE if one or all of the conditions are met, and returns FALSE only if no conditions are met.

These functions can test up to 255 conditions, so are certainly not limited to just two conditions like is demonstrated here.

Below is the structure of the AND and OR functions. They are written the same. Just substitute the name AND for OR. It is just their logic which is different.

=AND(logical1, [logical2] ...)

Let’s see an example of both of them evaluating two conditions.

AND Function example

The AND function is used below to test if the customer spends at least £3,000 and has been a customer for at least three years.

=AND(B2>=3000,C2>=3)

You can see that it returns FALSE for Matt and Terry because although they both meet one of the criteria, they need to meet both with the AND function.

OR Function Example

The OR function is used below to test if the customer spends at least £3,000 or has been a customer for at least three years.

=OR(B2>=3000,C2>=3)

In this example, the formula returns TRUE for Matt and Terry. Only Julie and Gillian fail both conditions and return the value of FALSE.

Using AND and OR with the IF Function

Because the AND and OR functions return the value of TRUE or FALSE when used alone, it’s rare to use them by themselves.

Instead, you’ll typically use them with the IF function, or within an Excel feature such as Conditional Formatting or Data Validation to perform some retrospective action if the formula evaluates to TRUE.

In the formula below, the AND function is nested inside the IF function’s logical test. If the AND function returns TRUE then 10% is discounted from the amount in column B; otherwise, no discount is given and the value in column B is repeated in column D.

=IF(AND(B2>=3000,C2>=3),B2*90%,B2)

The XOR Function

In addition to the OR function, there is also an exclusive OR function. This is called the XOR function. The XOR function was introduced with the Excel 2013 version.

This function can take some effort to understand, so a practical example is shown.

The structure of the XOR function is the same as the OR function.

=XOR(logical1, [logical2] ...)

When evaluating just two conditions the XOR function returns:

  • TRUE if either condition evaluates to TRUE.
  • FALSE if both conditions are TRUE, or neither condition is TRUE.

This differs from the OR function because that would return TRUE if both conditions were TRUE.

This function gets a little more confusing when more conditions are added. Then the XOR function returns:

  • TRUE if an odd number of conditions return TRUE.
  • FALSE if an even number of conditions result in TRUE, or if all conditions are FALSE.

Let’s look at a simple example of the XOR function.

In this example, sales are split over two halves of the year. If a salesperson sells £3,000 or more in both halves then they are assigned Gold standard. This is achieved with an AND function with IF like earlier in the article.

But if they sell £3,000 or more in either half then we want to assign them Silver status. If they don’t sell £3,000 or more in both then nothing.

The XOR function is perfect for this logic. The formula below is entered into column E and shows the XOR function with IF to display  “Yes” or “No” only if either condition is met.

=IF(XOR(B2>=3000,C2>=3000),"Yes","No")

The NOT Function

The final logical function to discuss in this article is the NOT function, and we have left the simplest for last. Although sometimes it can be hard to see the ‘real world’ uses of the function at first.

The NOT function reverses the value of its argument. So if the logical value is TRUE, then it returns FALSE. And if the logical value is FALSE, it will return TRUE.

This will be easier to explain with some examples.

The structure of the NOT function is;

=NOT(logical)

NOT Function Example 1

In this example, imagine we have a head office in London and then many other regional sites. We want to display the word “Yes” if the site is anything except London, and “No” if it is London.

The NOT function has been nested in the logical test of the IF function below to reverse the TRUE result.

=IF(NOT(B2="London"),"Yes","No")

This can also be achieved by using the NOT logical operator of . Below is an example.

=IF(B2"London","Yes","No")

NOT Function Example 2

The NOT function is useful when working with information functions in Excel. These are a group of functions in Excel that check something, and return TRUE if the check is a success, and FALSE if it is not.

For example, the ISTEXT function will check if a cell contains text and return TRUE if it does and FALSE if it does not. The NOT function is helpful because it can reverse the result of these functions.

In the example below, we want to pay a salesperson 5% of the amount they upsell. But if they did not upsell anything, the word “None” is in the cell and this will produce an error in the formula.

The ISTEXT function is used to check for the presence of text. This returns TRUE if there is text, so the NOT function reverses this to FALSE. And the IF performs its calculation.

=IF(NOT(ISTEXT(B2)),B2*5%,0)

Mastering logical functions will give you a big advantage as an Excel user. To be able to test and compare values in cells and perform different actions based on those results is very useful.

This article has covered the best logical functions used today. Recent versions of Excel have seen the introduction of more functions added to this library, such as the XOR function mentioned in this article. Keeping up to date with these new additions will keep you ahead of the crowd.