Forum Discussion

jonboylib's avatar
jonboylib
Iron Contributor
Aug 19, 2022

SP List Calculated Column Items Expiring Soon

I have a calculated column in my SP list (Renewal Date), it looks at another column (Date Purchased) and adds 4 years to it.

 

The formula in the calculated column is below;

 

 

=TEXT(DATE(YEAR([Date Purchased])+4,MONTH([Date Purchased]),DAY([Date Purchased])))

 

 

Now I would like to conditionally format the Renewal Date column, so that if the date is within 6 months of today, add a colour to the cell background, e.g. yellow. Or colour the text red/bold.

 

How can I achieve this?

    • jonboylib's avatar
      jonboylib
      Iron Contributor

      RobElliott Think i've figured it out using the code below. Converting 6 months to milliseconds - that correct?

       

      {
        "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
        "elmType": "div",
        "txtContent": "@currentField",
        "style": {
          "color": "=if(@currentField <= @now, '',if(@currentField <= @now + 15768000000 && @currentField > @now,'orange','green'))"
        }
      }

       

      • RobElliott's avatar
        RobElliott
        Silver Contributor
        Yes, date comparisons are always in milliseconds in JSON. Good stuff.

Resources