To calculate age and invoice status ("OK", "Paid", "Overdue") you can use a simple nested IF formula. In the example shown, the formula in G5 is:


As the formula is copied down, it returns "Paid" if there is an "x" in the "Paid" column. If there the invoice is not paid, the formula returns "OK" if the age is less than 31 days and "Overdue" if not.

Generic formula



The goal is to calculate the correct invoice status ("OK", "Paid", or "Overdue") using the following rules:

  1. If there is an "x" in the "Paid" column, return "Paid".
  2. If there is not an "x" in the "Paid" column, and if the age is less than 31 days, return "OK"
  3. If there is not an "x" in the "Paid" column, and if the age is not less than 31 days, return "Overdue"

This problem can be solved by nesting one IF function inside another.

Calculating age

To calculate invoice age in days, the formula in cell E5, copied down, uses the TODAY function:


This works because Excel dates are just serial numbers. At the time of this writing, the date is May 20, 2023. In Excel's date system, this is the number 45066. The due date of March 30, 2023, is the number 45015. Excel evaluates the formula above like this:


IF function

The IF function in Excel runs a test, then performs one action if the result is TRUE, and a different action if the result is FALSE. The generic syntax for IF looks like this:


The first argument is the logical test, and the second argument is the result (or calculation) to return when the test is TRUE. The third argument is the "else" — the value or calculation to return if the result of the logical test is FALSE.

IF paid

In the example shown, the first thing to check is if the invoice has been paid or not. We do this by checking the Paid column for an "x" as seen below. Notice that both "x" and "Paid" are enclosed in double quotes because they are text values:


Translation: If F5 equals "x", return "Paid".

At this point, we have not provided anything for the value if false. This means the IF function will return FALSE when F5 is empty. If this was the only thing we were checking, we might want to provide an empty string ("") like this:


In Excel, an empty string will not display anything. It will look like an empty cell.

IF overdue

The remaining task is to check the age of the invoice. To extend the formula to check for an overdue status, we use another IF formula like this:


Translation: If E5 is less than 31, return "OK", else return "Overdue".

Notice the value 31 is a number and therefore not enclosed in quotes. This formula will return "OK" for any age below 31 and "Overdue" for any age over 30. This number can be customized as desired.

The final step in the problem is to combine the two IF formulas above. We do this by starting off with the first IF:


Then we extend the formula by nesting the second IF inside the first IF:


Translation: If F5 equals "x", return "Paid". Else if E5 is less than 31, return "OK", else return "Overdue".



  1. The technique of placing one IF inside another is called "nesting" You will sometimes hear a formula like this called a "Nested IF formula". This page has many examples.
  2. Remember to enclose text values inside IF in double quotes ("") but do not quote numbers or operators. See How to use the IF function for more details.
Dave Bruns Profile Picture

AuthorMicrosoft Most Valuable Professional Award

Dave Bruns

Hi - I'm Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.