Forum Discussion

kuzya's avatar
kuzya
Frequent Visitor
3 years ago
Solved

Conditional Formatting Date Cells based on Status and Current Date

Hello Power Bi Community,   I need your support in determining if the following is possible using a table and conditional formatting in Power Bi. I have a set of data which includes a reccord/even...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi kuzya ,

    Please create four measure with below dax formula:

    Investigate Color =
    VAR _state =
        SELECTEDVALUE ( 'Table'[State] )
    VAR invest_date =
        SELECTEDVALUE ( 'Table'[Investigation Due Date] )
    VAR _today =
        TODAY ()
    VAR diff_date =
        DATEDIFF ( _today, invest_date, DAY )
    VAR _a =
        SWITCH (
            TRUE (),
            diff_date < 15, "red",
            diff_date < 30
                && diff_date > 15, "yellow"
        )
    VAR _val =
        SWITCH (
            _state,
            "Final", "green",
            "Plan", "green",
            "Investigation", _a,
            "Implementation", "green"
        )
    RETURN
        IF ( ISBLANK ( invest_date ), BLANK (), _val )
    
    Plan Color =
    VAR _state =
        SELECTEDVALUE ( 'Table'[State] )
    VAR plan_date =
        SELECTEDVALUE ( 'Table'[Plan Due Date] )
    VAR _today =
        TODAY ()
    VAR diff_date =
        DATEDIFF ( _today, plan_date, DAY )
    VAR _a =
        SWITCH (
            TRUE (),
            diff_date < 15, "red",
            diff_date < 30
                && diff_date > 15, "yellow",
            diff_date > 30, "green"
        )
    VAR _val =
        SWITCH (
            _state,
            "Final", "green",
            "Plan", _a,
            "Investigation", _a,
            "Implementation", "green"
        )
    RETURN
        IF ( ISBLANK ( plan_date ), BLANK (), _val )
    
    Imple Color =
    VAR _state =
        SELECTEDVALUE ( 'Table'[State] )
    VAR imple_date =
        SELECTEDVALUE ( 'Table'[Implementation Due Date] )
    VAR _today =
        TODAY ()
    VAR diff_date =
        DATEDIFF ( _today, imple_date, DAY )
    VAR _a =
        SWITCH (
            TRUE (),
            diff_date < 15, "red",
            diff_date < 30
                && diff_date > 15, "yellow"
        )
    VAR _val =
        SWITCH (
            _state,
            "Final", "green",
            "Plan", "green",
            "Investigation", _a,
            "Implementation", _a
        )
    RETURN
        IF ( ISBLANK ( imple_date ), BLANK (), _val )
    
    Final Color =
    VAR _state =
        SELECTEDVALUE ( 'Table'[State] )
    VAR final_date =
        SELECTEDVALUE ( 'Table'[Final Due Date] )
    VAR _today =
        TODAY ()
    VAR diff_date =
        DATEDIFF ( _today, final_date, DAY )
    VAR _a =
        SWITCH (
            TRUE (),
            diff_date < 15, "red",
            diff_date < 30
                && diff_date > 15, "yellow",
            diff_date > 30, "green"
        )
    VAR _val =
        SWITCH (
            _state,
            "Final", "green",
            "Plan", "green",
            "Investigation", _a,
            "Implementation", _a
        )
    RETURN
        IF ( ISBLANK ( final_date ), BLANK (), _val )
    

     

    Add a table visual with table fields and configure conditional format with measure:

    Please refer the attached .pbix file.

     

    Best regards,
    Community Support Team_Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.