Logical Formulas in excel
Logical formulas in Excel are used to perform operations based on logical conditions. These formulas evaluate whether a given condition is true or false and then perform a specified action accordingly. Here are some commonly used logical formulas in Excel:
IF Function:
- Syntax:
=IF(logical_test, value_if_true, value_if_false) - Example:
=IF(A1>10, "Yes", "No") - This formula checks if the value in cell A1 is greater than 10. If true, it returns "Yes"; otherwise, it returns "No".
- Syntax:
AND Function:
- Syntax:
=AND(logical1, logical2, ...) - Example:
=AND(A1>10, B1<20) - Returns TRUE if both conditions (A1 > 10 and B1 < 20) are true; otherwise, it returns FALSE.
- Syntax:
OR Function:
- Syntax:
=OR(logical1, logical2, ...) - Example:
=OR(A1="Apple", A1="Banana") - Returns TRUE if at least one of the conditions (A1 is "Apple" or A1 is "Banana") is true; otherwise, it returns FALSE.
- Syntax:
NOT Function:
- Syntax:
=NOT(logical) - Example:
=NOT(A1="Closed") - Returns TRUE if the condition (A1 is not "Closed") is false; otherwise, it returns FALSE.
- Syntax:
IFERROR Function:
- Syntax:
=IFERROR(value, value_if_error) - Example:
=IFERROR(A1/B1, "Error in calculation") - Returns the result of the division in A1 by B1 unless there is an error, in which case it returns "Error in calculation".
IF AND OR Combination:
- Syntax:
=IF(AND(logical1, logical2), value_if_true, value_if_false) - Example:
=IF(AND(A1>10, B1<20), "Yes", "No") - Returns "Yes" if both conditions (A1 > 10 and B1 < 20) are true; otherwise, it returns "No".
- Syntax:
IF with Nested IF Statements:
- Syntax:
=IF(logical_test1, value_if_true1, IF(logical_test2, value_if_true2, value_if_false2)) - Example:
=IF(A1>10, "High", IF(A1>5, "Medium", "Low")) - Nested IF statement that categorizes values in cell A1 as "High," "Medium," or "Low" based on different conditions.
- Syntax:
XOR Function (Exclusive OR):
- Syntax:
=XOR(logical1, logical2) - Example:
=XOR(A1>10, B1<20) - Returns TRUE if either logical1 is true or logical2 is true, but not both.
- Syntax:
COUNTIF Function:
- Syntax:
=COUNTIF(range, criteria) - Example:
=COUNTIF(A1:A10, ">50") - Counts the number of cells in the range A1:A10 that are greater than 50.
- Syntax:
SUMIF Function:
- Syntax:
=SUMIF(range, criteria, sum_range) - Example:
=SUMIF(A1:A10, ">50", B1:B10) - Adds up the values in the range B1:B10 corresponding to cells in A1:A10 that meet the criteria (>50).
IF Statement with Multiple Conditions (Using AND and OR):
- Syntax:
=IF(AND(condition1, OR(condition2, condition3)), value_if_true, value_if_false) - Example:
=IF(AND(A1>10, OR(B1="High", B1="Medium")), "Yes", "No") - Returns "Yes" if A1 is greater than 10 and B1 is either "High" or "Medium"; otherwise, it returns "No".
- Syntax:
IFS Function (Multiple IF Conditions):
- Syntax:
=IFS(condition1, value_if_true1, condition2, value_if_true2, ..., value_if_false) - Example:
=IFS(A1>10, "High", A1>5, "Medium", A1<=5, "Low") - Evaluates multiple conditions and returns the corresponding value for the first true condition.
- Syntax:
CHOOSE Function (Selecting Values Based on Index):
- Syntax:
=CHOOSE(index, value1, value2, ...) - Example:
=CHOOSE(A1, "Option 1", "Option 2", "Option 3") - Returns the value at the position specified by the value in cell A1.
- Syntax:
IFNA Function (Handling #N/A Errors):
- Syntax:
=IFNA(value, value_if_na) - Example:
=IFNA(VLOOKUP(A1, B1:C10, 2, FALSE), "Not Found") - Returns the result of the VLOOKUP function unless it results in #N/A error, in which case it returns "Not Found".
- Syntax:
IFERROR with VLOOKUP (Handling Errors):
- Syntax:
=IFERROR(formula, value_if_error) - Example:
=IFERROR(VLOOKUP(A1, B1:C10, 2, FALSE), "Error") - Returns the result of the VLOOKUP function unless there is an error, in which case it returns "Error".
IFS Function:
- Syntax:
=IFS(condition1, value_if_true1, condition2, value_if_true2, ...) - Example:
=IFS(A1>90, "A", A1>80, "B", A1>70, "C", TRUE, "Fail") - Returns a grade based on the value in cell A1. If A1 is greater than 90, it returns "A," if greater than 80, it returns "B," and so on.
- Syntax:
IFERROR with VLOOKUP:
- Syntax:
=IFERROR(VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup]), "Not Found") - Example:
=IFERROR(VLOOKUP(A1, $B$1:$D$100, 2, FALSE), "Not Found") - Uses VLOOKUP to search for a value in column B and returns the corresponding value from column C. If an error occurs, it returns "Not Found."
- Syntax:
MATCH Function:
- Syntax:
=MATCH(lookup_value, lookup_array, [match_type]) - Example:
=MATCH("Apple", A1:A10, 0) - Returns the relative position of "Apple" within the range A1:A10. The match_type 0 ensures an exact match.
- Syntax:
IF with ISBLANK Function:
- Syntax:
=IF(ISBLANK(A1), "Blank", "Not Blank") - Example: Checks if cell A1 is blank. If true, it returns "Blank"; otherwise, it returns "Not Blank."
- Syntax:
LEN Function for Text Length:
- Syntax:
=LEN(A1) - Example:
=LEN("Excel") - Returns the number of characters in cell A1 or the specified text. In this example, it returns 5.
COUNTIFS Function:
- Syntax:
=COUNTIFS(range1, criteria1, range2, criteria2, ...) - Example:
=COUNTIFS(A1:A10, ">50", B1:B10, "<100") - Counts the number of cells in A1:A10 where the value is greater than 50 and simultaneously in B1:B10 where the value is less than 100.
- Syntax:
SUMIFS Function:
- Syntax:
=SUMIFS(sum_range, range1, criteria1, range2, criteria2, ...) - Example:
=SUMIFS(C1:C10, A1:A10, "Apples", B1:B10, "January") - Adds up the values in C1:C10 where the corresponding cells in A1:A10 contain "Apples" and B1:B10 contain "January."
- Syntax:
TEXT Function with IF:
- Syntax:
=IF(A1>0, TEXT(A1, "0.00"), "Negative") - Example: Formats the positive values in cell A1 with two decimal places using the TEXT function. If A1 is negative, it returns "Negative."
- Syntax:
Logical Formulas with Dates:
- Syntax:
=IF(TODAY()>A1, "Past", "Future") - Example: Compares the date in cell A1 with the current date. If A1 is in the past, it returns "Past"; otherwise, it returns "Future."
- Syntax:
IF with ISNUMBER and SEARCH:
- Syntax:
=IF(ISNUMBER(SEARCH("apple", A1)), "Contains Apple", "No Apple") - Example: Checks if cell A1 contains the word "apple" (case-insensitive). If true, it returns "Contains Apple"; otherwise, it returns "No Apple."
CHOOSE Function:
- Syntax:
=CHOOSE(index_num, value1, value2, ...) - Example:
=CHOOSE(A1, "Option 1", "Option 2", "Option 3") - Returns the value based on the index number in cell A1. For example, if A1 is 2, it returns "Option 2."
- Syntax:
IF with ISTEXT:
- Syntax:
=IF(ISTEXT(A1), "Text", "Not Text") - Example: Checks if the content in cell A1 is text. If true, it returns "Text"; otherwise, it returns "Not Text."
- Syntax:
IFS with Wildcards:
- Syntax:
=IFS(ISNUMBER(SEARCH("apple", A1)), "Fruit", ISNUMBER(SEARCH("car", A1)), "Vehicle", TRUE, "Other") - Example: Uses IFS to categorize the content in cell A1 based on whether it contains "apple" (Fruit), "car" (Vehicle), or neither (Other).
- Syntax:
IF with TODAY and EDATE:
- Syntax:
=IF(TODAY()>EDATE(A1, 3), "Expired", "Active") - Example: Checks if the date in cell A1 is more than 3 months ago. If true, it returns "Expired"; otherwise, it returns "Active."
- Syntax:
INDEX and MATCH Combination:
- Syntax:
=INDEX(B1:B10, MATCH(MAX(A1:A10), A1:A10, 0)) - Example: Finds the maximum value in A1:A10 and returns the corresponding value from B1:B10 using INDEX and MATCH.
- IF with OR and AND:
- Syntax:
=IF(OR(A1>10, AND(B1<5, C1="Yes")), "Condition Met", "Condition Not Met") - Example: Checks if either A1 is greater than 10 or both B1 is less than 5 and C1 is "Yes." If true, it returns "Condition Met"; otherwise, it returns "Condition Not Met."
- INDEX and MATCH for Dynamic Lookups:
- Syntax:
=INDEX($C$1:$C$100, MATCH(MAX($B$1:$B$100), $B$1:$B$100, 0)) - Example: Retrieves the value from column C corresponding to the maximum value in column B, creating a dynamic lookup.
- IF with DATE Function:
- Syntax:
=IF(DATE(YEAR(A1), MONTH(A1)+3, DAY(A1))<TODAY(), "Older Than 3 Months", "Within 3 Months") - Example: Compares the date in cell A1 with a date that is 3 months later. If the date is older, it returns "Older Than 3 Months"; otherwise, it returns "Within 3 Months."
- Nested IF Statements for Grading:
- Syntax:
=IF(A1>=90, "A", IF(A1>=80, "B", IF(A1>=70, "C", "Fail"))) - Example: Uses nested IF statements to assign grades based on the value in cell A1.
- IF with ISEMPTY:
- Syntax:
=IF(ISEMPTY(A1), "Empty", "Not Empty") - Example: Checks if cell A1 is empty. If true, it returns "Empty"; otherwise, it returns "Not Empty."
- IF with MOD Function:
- Syntax:
=IF(MOD(A1, 2) = 0, "Even", "Odd") - Example: Determines if the value in cell A1 is even or odd using the MOD function within an IF statement.
- COUNTIF with Multiple Criteria:
- Syntax:
=COUNTIFS(A1:A10, ">50", B1:B10, "Red") - Example: Counts the number of cells where the value in column A is greater than 50 and the value in column B is "Red."
- SUMPRODUCT for Weighted Average:
- Syntax:
=SUMPRODUCT(A1:A5, B1:B5) / SUM(B1:B5) - Example: Calculates the weighted average of values in column A based on weights in column B using SUMPRODUCT.
- IF with ISTIME:
- Syntax:
=IF(ISTIME(A1), "Time", "Not Time") - Example: Checks if the value in cell A1 is a valid time. If true, it returns "Time"; otherwise, it returns "Not Time."
- INDEX and MATCH with Multiple Criteria:
- Syntax:
=INDEX(D1:D10, MATCH(1, (A1:A10="Apples")*(B1:B10="Red"), 0)) - Example: Retrieves a value from column D where column A is "Apples" and column B is "Red" using INDEX and MATCH with multiple criteria.
- IF with ISNUMBER and FIND for Substring Search:
- Syntax:
=IF(ISNUMBER(FIND("excel", A1)), "Contains 'excel'", "Doesn't Contain 'excel'") - Example: Checks if the text in cell A1 contains the substring "excel." If true, it returns "Contains 'excel'"; otherwise, it returns "Doesn't Contain 'excel'."
- SUMPRODUCT for Multiple Conditions:
- Syntax:
=SUMPRODUCT((A1:A10="Apples")*(B1:B10="Red")*(C1:C10>5), D1:D10) - Example: Calculates the sum of values in column D where conditions are met in columns A, B, and C using SUMPRODUCT.
- IF with WEEKDAY Function:
- Syntax:
=IF(WEEKDAY(A1)=1, "Sunday", "Not Sunday") - Example: Determines if the date in cell A1 falls on a Sunday using the WEEKDAY function within an IF statement.
- INDEX and MATCH with Approximate Match:
- Syntax:
=INDEX(C1:C10, MATCH(MAX(A1:A10), A1:A10, 1)) - Example: Retrieves the value from column C corresponding to the maximum value in column A using INDEX and MATCH with an approximate match.
- IF with NETWORKDAYS Function:
- Syntax:
=IF(NETWORKDAYS(A1, B1)>5, "More than 5 workdays", "5 or fewer workdays") - Example: Checks if the number of workdays between dates in cells A1 and B1 is more than 5 using the NETWORKDAYS function within an IF statement.
- IF with ISTEXT and LEN for Text Length Validation:
- Syntax:
=IF(ISTEXT(A1), IF(LEN(A1)<=10, "Valid", "Too Long"), "Not Text") - Example: Checks if cell A1 contains text. If true, it further checks if the length is less than or equal to 10 characters, returning "Valid" or "Too Long" accordingly.
- IFS with ISTEXT and ISNUMBER:
- Syntax:
=IFS(ISTEXT(A1), "Text", ISNUMBER(A1), "Number", TRUE, "Other") - Example: Categorizes the content in cell A1 as "Text," "Number," or "Other" using the IFS function based on whether it is text or a number.
- SUMPRODUCT with Multiple Criteria and Wildcards:
- Syntax:
=SUMPRODUCT((A1:A10="*apple*")*(B1:B10="Red"), C1:C10) - Example: Calculates the sum of values in column C where column A contains the word "apple" (using wildcards) and column B is "Red."
- IF with WORKDAY Function:
- Syntax:
=IF(WORKDAY(A1, 5)<TODAY(), "More than 5 workdays ago", "5 or fewer workdays ago") - Example: Checks if the date 5 workdays after the date in cell A1 is more than 5 workdays ago using the WORKDAY function within an IF statement.
- IFS with Logical Tests:
- Syntax:
=IFS(A1<0, "Negative", A1=0, "Zero", A1>0, "Positive") - Example: Categorizes the value in cell A1 as "Negative," "Zero," or "Positive" using the IFS function based on different logical tests.
- Syntax:
Comments
Post a Comment