Sub topic 5
Combining flags with AND, OR, and multiplication
This chapter assumes you can copy formulas across a row with correct anchored references, and that you have already built a single 1/0 timing flag with IF. Here you will combine several flags into one. You will learn three methods, what each one returns, and where each one fails.
Why combine flags
A single flag answers one question, such as "Is this period on or after the start date?" Real line items usually depend on several conditions at once:
- A bonus is paid only between a start and an end period.
- A cost applies only in the base scenario and only after a launch date.
- A fee is charged if the loan is drawn or the facility is committed.
You could write one long IF for each case. A better habit is to keep each condition in its own flag row and combine the rows in a short formula. Each flag row can then be checked by itself.
The sample layout
The examples use this layout. Periods run across columns F onward, and the dates are in row 5. Inputs sit in column C.
| Row | Label | Column C | Column F onward |
|---|---|---|---|
| 5 | Period end date | Dates | |
| 10 | Start date | Input | |
| 11 | End date | Input | |
| 12 | Launch date | Input | |
| 20 | Bonus amount | Amounts | |
| 30 | Started flag | 1/0 | |
| 31 | Not ended flag | 1/0 | |
| 32 | Scenario is upside flag | 1/0 |
Rows 30 and 31 are the two halves of a timing flag. Each is a separate row so you can read it and test it on its own.
=IF(F$5>=$C$10,1,0)This is the started flag in row 30. It returns 1 once the period date reaches the start date.
=IF(F$5<=$C$11,1,0)This is the not-ended flag in row 31. It returns 1 until the period date passes the end date.
Method 1: AND and OR inside IF
AND returns TRUE only when every condition is TRUE. OR returns TRUE when at least one condition is TRUE. Wrap either in IF to get a 1/0 result.
The timing flag from the topic plan uses AND:
=IF(AND(F$5>=$C$10,F$5<=$C$11),1,0)The formula returns 1 only when the date is on or after the start and on or before the end. Before the start, the first test fails. After the end, the second test fails. Either failure gives 0.
OR works the same way, but one TRUE is enough. This formula returns 1 if the period falls before the start date or after the end date. That is the opposite of the timing flag, useful for a "blackout" period:
=IF(OR(F$5<$C$10,F$5>$C$11),1,0)You can nest the two, for example =IF(AND(F$5>=$C$10,OR($C$2=1,$C$2=2)),1,0). Keep nesting shallow. Past two levels, split the logic into separate flag rows.
Method 2: multiplying flags
Because a flag is 1 or 0, multiplying flags works like AND. The product is 1 only when every flag is 1. A single 0 makes the product 0.
=F30*F31This gives the same result as the AND version, using the two flag rows built earlier. Multiplication scales to more conditions without nesting:
=F30*F31*F32The truth table shows why multiplication matches AND for 1/0 values.
| Flag A | Flag B | A × B | AND result |
|---|---|---|---|
| 0 | 0 | 0 | FALSE |
| 0 | 1 | 0 | FALSE |
| 1 | 0 | 0 | FALSE |
| 1 | 1 | 1 | TRUE |
You can apply the combined flag directly to a line item, as in the topic's example of multiplying a line item by a timing flag:
=F20*F$8Here row 8 holds the final combined flag. The amount in row 20 passes through when the flag is 1 and becomes zero when the flag is 0.
Method 3: adding flags for OR
Addition behaves like OR, with one catch. 1 + 0 gives 1, which is correct. But 1 + 1 gives 2, not 1. A flag of 2 will double your line item when you multiply by it.
Cap the sum at 1 with MIN:
=MIN(1,F30+F32)This returns 1 if either flag is 1, and also 1 if both are. MIN here acts as a cap, an idea the next chapters develop in full. Without it, overlapping conditions silently double-count.
Comparing the three methods
| Method | Example | Strength | Weakness |
|---|---|---|---|
| IF with AND/OR | `=IF(AND(A,B),1,0)` | Reads like a sentence. One cell shows the full rule. | Conditions are buried inside the formula. Long formulas are hard to audit. |
| Multiplication | `=F30*F31` | Short. Each condition has its own visible row. Scales to many flags. | Only works if every input is truly 1 or 0. Does not express OR. |
| Addition with MIN | `=MIN(1,F30+F32)` | Expresses OR on flag rows. | Easy to forget the cap, which gives values of 2 or more. |
A practical rule: use separate flag rows for each condition, then combine them with multiplication for AND and MIN(1, sum) for OR. Use IF with AND/OR when the whole rule is simple enough to read at a glance.
A worked example
A bonus equals 10% of a base amount, capped at a maximum. It is paid only from the start date through the end date, and only in the upside scenario. Inputs:
- C3: bonus rate, 10%
- C4: bonus cap
- C2: scenario number, where 2 means upside
- C10 and C11: start and end dates
Build the model in steps.
- Row 30, started flag:
=IF(F$5>=$C$10,1,0) - Row 31, not-ended flag:
=IF(F$5<=$C$11,1,0) - Row 32, upside flag:
=IF($C$2=2,1,0) - Row 8, combined flag:
=F30*F31*F32 - Row 21, bonus:
=MIN(F20*$C$3,$C$4)*F$8
Step 5 applies the cap first, then the flag. Reversing the order gives the same number here, because the flag is only 1 or 0. The cap-then-flag order keeps the cap logic visible and leaves the flag as the last, simple gate.
Notice that row 32 is the same on every column. It depends only on the anchored cell $C$2. That is fine and intentional, since a scenario does not vary by period. Some modelers still keep it as a full row so the combined formula is identical across the whole timeline.
Edge cases and common errors
Flags that are not exactly 1 or 0
Multiplication assumes clean 1/0 values. If a flag row returns TRUE and FALSE, Excel will usually treat them as 1 and 0 inside arithmetic like *, but some functions and add-ins do not. A text value such as "1" typed as a string breaks the arithmetic or gives a #VALUE! error. Build flags with IF so the output is always a number.
Blank cells
A blank date cell counts as 0 in comparisons. If the end date in C11 is empty, F$5<=$C$11 is FALSE for every real date, so the not-ended flag is 0 everywhere and the item never appears. Decide on a rule for open-ended items. One option is to enter a far-future date such as 31 December 2099 as the end date. Another is to test for blanks:
=IF(AND(F$5>=$C$10,OR($C$11="",F$5<=$C$11)),1,0)This returns 1 when the date is on or after the start and either no end date is given or the date is on or before the end.
Mixing up AND and OR
A frequent mistake is writing OR where the rule needs AND. For a window between a start and an end date, OR(F$5>=$C$10,F$5<=$C$11) is TRUE for every date, because any date is either after the start or before the end. The flag is then always 1. Test each flag with a date before, inside, and after the window to catch this.
Dates compared with different granularity
If period dates are month ends and the start date is the first of a month, the comparison F$5>=$C$10 includes the month containing the start date. That may or may not be what you want. Document the rule beside the input, for example "Start date: first period ending on or after this date."
Copying errors
Anchor the input cells with $ and the row of the dates with F$5. If you write F5 instead of F$5, copying the formula down to another row shifts the reference to a different row and silently returns wrong flags.
A checking routine
Before you trust a combined flag, run these checks:
- Sum each flag row across the timeline. The count of 1s should match the number of periods you expect.
- Change the start and end dates to move the window, and confirm the flag moves with them.
- Set the scenario to each value and confirm the scenario flag is 1 in only one case.
- Confirm the combined flag never exceeds 1 using
=MAX(F8:Z8). - Confirm a line item is zero in periods where the flag is 0.
Exercises
Exercise
A cost should apply when the period date is on or after the launch date in C12 AND the scenario number in C2 equals 1 (base). Write the combined flag as one IF formula, and then as a product of two flag cells in F40 and F41.
Show answer
One formula: =IF(AND(F$5>=$C$12,$C$2=1),1,0). Product version, with F40 =IF(F$5>=$C$12,1,0) and F41 =IF($C$2=1,1,0): =F40*F41. Both return 1 only when both conditions hold.
Exercise
A fee applies if either a loan flag in F50 or a facility flag in F51 is 1. Both can be 1 in the same period. Write a formula that returns exactly 1 or 0, and explain what goes wrong with =F50+F51.
Show answer
Use =MIN(1,F50+F51), or =IF(OR(F50=1,F51=1),1,0). The plain sum returns 2 when both flags are 1, so multiplying a fee by that flag would charge it twice.
Exercise
The end date in C11 is blank because the item has no end. The flag =IF(AND(F$5>=$C$10,F$5<=$C$11),1,0) returns 0 in every period. Why, and how do you fix it?
Show answer
A blank cell is treated as 0, so F$5<=$C$11 compares each date with 0 and is FALSE. Fix it by allowing a blank end date: =IF(AND(F$5>=$C$10,OR($C$11="",F$5<=$C$11)),1,0). Alternatively, enter a far-future date as the end date.