Correct Nesting Formula?

Hi. I’m looking to track how much time (in days) a lead spends in each stage in a pipeline. I’m basing it on start and stop dates of time in stage. The formula I’m trying to accomplish is this (hope it makes sense):

Is the start date blank?

  1. YES: Do nothing, stay blank. (end)
  2. NO: (ask) Is the end date blank?
    —1. YES: Subtract today’s date from start date
    —2. NO: Subtract end date from start date

I came up with the following but I just get an error that the formula isn’t correct.

IF({Start Date} = BLANK(), “”, IF({End Date} = BLANK(), DATETIME_DIFF(TODAY(),{Start Date}, ‘days’), DATETIME_DIFF({End Date}, {Start Date}, ‘days’)

What’s not working?!

Definitely new to AirTable and formulas in general so if there is another way to approach this, I’m all ears! :). Thanks!

The rest of your formula is a mathematic function that should result in a number, but your first condition results in an empty string.

In Airtable, you want to say “If field is blank do nothing”, you get the same result as “Do something if the field has a value” without risking putting strings where numbers/dates should be.

The other issue with your formula is its missing closing parentheses for the first IF.

  {Start Date},
    IF({End Date}, {End Date}, TODAY()),
    {Start Date}, 

Since the DATETIME_DIFF function’s only variable was the first date, I just used the function once with an IF inside it.

This works perfect. I’ll study and keep in mind for the future. Thank you!

I tend to simplify formulas down as much as possible. If you’re curious, the correct syntax for your original method would be:

  {Start Date} = BLANK(),
    {End Date} = BLANK(), 
    DATETIME_DIFF(TODAY(),{Start Date}, 'days'), 
    DATETIME_DIFF({End Date}, {Start Date}, 'days')
1 Like

Yeah. This is a thing of beauty!

This topic was solved and automatically closed 3 days after the last reply. New replies are no longer allowed.