Microsoft Tech Community - Latest Blogs - Excel Blog

السبت، 20 أغسطس 2022

The IF function

 

The IF function allows you to ask a question then act in one of two ways based on the answer.

The question you ask must be answerable as “True” or “False” and nothing else

.

The formula looks like so: ask a question, then perform action “A” if true or perform action “B” if it’s false.

In the below example, we want to audit any “Amount” over “20,000”.  We could say, “If the value in cell D2 is greater than 20000 then display the word “Check”.  Otherwise, display nothing.”

=IF(D2 > 20000, "Check", "")

We can see that any amount more than 20,000 displays the “Check” message, while other cells display nothing.

NOTE: The use of the 2 double quotes is Excel’s way of saying “display nothing” (empty text).

PRO TIP: It’s best to place the 20,000 value in a separate cell and reference the cell as opposed to hard-coding the 20,000 into the IF formula.  This way, you can more easily see what the “Amount” threshold is and if you need to change the threshold, you can change the single-cell value and update all the IF formulas in a single update.

=IF(D2 > H1, “Check”, “”)

You can check for multiple conditions by either nesting an IF within another IF (you can do this up to 64 times) or you can use an IFS function that allows up to 127 logical declarations, although this is not recommended.  Once you get past needing 10 or more decisions, there are usually alternate strategies that will perform better with less logical construction.

To see an ingenious use of wildcards for performing partial text matches with IF, check out the link below.

ليست هناك تعليقات:

إرسال تعليق