Is there a way to reference columns in SharePoint lists when conditional formatting?

Rodman Stuhlmuller 1 Reputation point
2021-07-27T18:43:00.45+00:00

I want to highlight dates when they are past due. (Completion date IS AFTER Due date). Right now my only options for the date is Today or a specific date, but I want to be able to choose another column.

Microsoft 365 and Office | SharePoint | For business | Windows
{count} votes

1 answer

Sort by: Most helpful
  1. JoyZ 18,126 Reputation points
    2021-07-28T02:52:12.787+00:00

    @Rodman Stuhlmuller ,

    We could use the [$FieldName] syntax to look at the value inside another field in column formatting.

    FieldName is assumed to be the internal name of the field.

    Simple test for your reference:

    1. Find the internal name of another field via list settings>click on the specified column under Columns option, check the url of the column to get the internal name:
      List item
    2. Format the "Completion date" column as shown below:

    118475-image.png

    Code:

    {  
    "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",  
    "elmType": "div",  
    "txtContent": "@currentField",  
    "attributes": {  
    "class": "=if(@currentField >= [$Duedate], 'ms-fontColor-orange ms-fontWeight-bold', '')"  
      }   
    }  
    

    More information for your reference:

    https://learn.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting#formatting-an-item-when-a-date-column-is-before-or-after-todays-date-advanced


    If an Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    2 people found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.