Forum Discussion

PC2022's avatar
PC2022
Helper III
4 years ago
Solved

Nested IF - dates

Hello, I need to create DAX for date KPI but i am practicing in excel first, so i could create formula in Power BI later.   Green - today is greater than 45 day period leading up to the finish dat...
  • amitchandak's avatar
    4 years ago

    PC2022 , Create a new column like 

     

    =

    var _diff = datediff([finish date], today(), day)

    return

    Switch(True(),

    _diff >=45 , "Green",

    _diff > 0 , "Yellow",

    "Red"

    )

     

    you can use this column in conditional formatting using the field value option

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi PC2022,

    In fact, you can use one calculated column to achieve these, you only need to add a variable to store the first step result and use the switch function to check the diff and return color code.

    Color code =
    VAR _diff =
        DATEDIFF ( [finish date], TODAY (), DAY )
    RETURN
        SWITCH ( TRUE (), _diff >= 45, "Green", _diff > 0, "Yellow", "Red" )

    After these steps, you can right-click on your field that needs to be formatted with 'field value' mode based on the above 'color code' column field values.

    Apply conditional table formatting in Power BI - Power BI | Microsoft Docs

    Regards,

    Xiaoxin Sheng