Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Help with Date Conditional Formatting (Due Date)

Hello!

 

I need help in using conditional formatting for dates.

I have a column for due dates and would want a color coded value when it's far from due date, almost due date and beyond due date.

 

For example.

I want Task Number and Due date background turned GREEN if it's far from it's due date.

ORANGE if it's close to its due date and

RED if it's beyond its due date.

 

  • MFelix's avatar
    MFelix
    5 years ago

    Hi Anonymous ,

     

    This is a measure and you should replace the ";" by ",".

     

    CondittionalFormatting =
    VAR number_of_days =
        SELECTEDVALUE ( 'Table'[Due Date] ) - TODAY ()
    RETURN
        SWITCH (
            TRUE (),
            number_of_days < 0, "Red",
            number_of_days < 10, "Orange",
            "Green"
        )

     

    The number_of_days is a variable is calculated on top as you can see tha make the difference between the due date and today.

6 Replies

  • Hi Anonymous ,

     

    What is the condition to have it Close/Far from due date?

     

    If you create a measure similar to the one below you can have the desired result:

     

    CondittionalFormatting =
    VAR number_of_days =
        SELECTEDVALUE ( 'Table'[Due Date] ) - TODAY ()
    RETURN
        SWITCH (
            TRUE ();
            number_of_days < 0; "Red";
            number_of_days < 10; "Orange";
            "Green"
        )

    Just adjust the 10 days to whatever value you need then use it as your condittional formatting:

     
    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello! Thank you for your response.

      Should I just add a measure?

      Where do I get number_of_days?

      I get red lines. Sorry I'm, not too good with codes.

       

      • MFelix's avatar
        MFelix
        Super User

        Hi Anonymous ,

         

        This is a measure and you should replace the ";" by ",".

         

        CondittionalFormatting =
        VAR number_of_days =
            SELECTEDVALUE ( 'Table'[Due Date] ) - TODAY ()
        RETURN
            SWITCH (
                TRUE (),
                number_of_days < 0, "Red",
                number_of_days < 10, "Orange",
                "Green"
            )

         

        The number_of_days is a variable is calculated on top as you can see tha make the difference between the due date and today.