Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

Nested IF formula optimization

Maybe it's obvious but somehow I got stuck with this formula. I'm convinced there is a better way to formulate this, but just can't figure it out. To make it worse, it doesn't work correctly :smileyf...
  • Greg_Deckler's avatar
    8 years ago

    One thing you could do would be to define this variable:

     

    VAR LastModifiedDuration = backlogRecord[Date modified], NOW (), HOUR )

     

    Also, I would switch to a SWITCH statement.

  • Anonymous's avatar
    Anonymous
    8 years ago

    Greg_Deckleryes it did the trick! Thank you. Here's my new formula for that calculated column:

     

    backlogHealth =
    VAR hoursElapsed =
        DATEDIFF ( backlogRecord[Date modified], NOW (), HOUR )
    RETURN
        SWITCH (
            TRUE (),
            hoursElapsed > 168, "Retired",
            WEEKDAY ( NOW () ) = 7
                && hoursElapsed > 48, "Missing",
            WEEKDAY ( NOW () ) = 1
                && hoursElapsed > 72, "Missing",
            WEEKDAY ( NOW () ) < 7
                && hoursElapsed > 24, "Missing",
            HOUR ( backlogRecord[Date modified] ) < 10, "OK",
            HOUR ( backlogRecord[Date modified] ) < 12, "Pending",
            "Delayed"
        )