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.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,969 questions
{count} votes

1 answer

Sort by: Most helpful
  1. JoyZ 18,076 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 Answers by the question author, which helps users to know the answer solved the author's problem.