Forum Discussion
Conditional Formatting Date Cells based on Status and Current Date
- Anonymous3 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.
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.
Anonymous ,
This is great! Thank you so much for your support on this. I was able to align your code with my .pbix file and it works as intended. Something to note, I changed the colors to match conditional formating from excel. The hex colors are: Red "#FFC7CE", Yellow "#FFEB9C", and green "#C6EFCE". The output looks like this:
Also, as you can see in line 7 under Effectiveness Due Date, it should be yellow as is between 30 and 15 days from todays date (6/5/2023). To fix this, I am using the variable _a and it now reflects the appropriate format.
I will continue monitoring to determine if additional changes are needed.
Regards!