Skip to main content

How to Add List Validation in SharePoint to Compare Two Columns

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

Column settings can check one column at a time. List validation checks a whole item when it's saved, so it can compare columns: a finish after its start, an end date after a begin date, a discount below the price. If the formula isn't TRUE, SharePoint refuses the item and shows your message.

The OvertimeEntries list of the Overtime Timesheet series holds one item per shift, with StartTime, EndTime and BreakMinutes. Its rule: the finish must be after the start, no more than 24 hours later, and the break must be shorter than the shift.

Prerequisites​

  • A SharePoint list with the columns to compare, and permission to change its settings.
  • Basic formulas. SharePoint formulas work like Excel's. Microsoft's calculatedColumn reference says "SharePoint formulas use a syntax similar to Excel formulas."

Step 1: Open List Settings​

In the list, select Settings (the gear) → List settings:

The SharePoint Settings panel with List settings outlined in red, between Site contents and Site information

Step 2: Open Validation Settings​

Under General Settings, select Validation settings:

The General Settings section of List settings with List name, description and navigation, Versioning settings, Advanced settings, Validation settings outlined in red, Audience targeting settings and Form settings

Step 3: Write the Formula and the Message​

The page has two boxes. Formula: "To pass validation, the formula must evaluate to TRUE." User Message: what people see when it doesn't. The Insert Column list next to the formula adds a column's name for you.

This is the formula for OvertimeEntries:

A code window titled OvertimeEntries → List validation showing =AND([EndTime]>[StartTime],[EndTime]-[StartTime]<=1,[BreakMinutes]<([EndTime]-[StartTime])*1440), which passes only when the shift ends after it starts, lasts no more than a day, and is longer than its break

OvertimeEntries → Validation settings → Formula
=AND([EndTime]>[StartTime],[EndTime]-[StartTime]<=1,[BreakMinutes]<([EndTime]-[StartTime])*1440)

Read it piece by piece:

  • Column names go in square brackets: [EndTime] is the value of the EndTime column.
  • AND(…) is TRUE only when all three conditions are.
  • [EndTime]>[StartTime]: the shift finishes after it starts. Microsoft's Examples of common formulas in lists uses the same comparison, =[Column1]>[Column2].
  • [EndTime]-[StartTime]<=1: subtracting two dates gives days, so this means no more than 24 hours.
  • [BreakMinutes]<([EndTime]-[StartTime])*1440: a day has 1,440 minutes, so this turns the shift's length into minutes and checks the break is shorter.

The same arithmetic works in Excel, where the overtime workbook of Part 1 used it: How to Calculate Hours Between Two Times in Excel and How to Convert Minutes to a Time in Excel by Dividing by 1440.

In User Message, write what's wrong and how to fix it:

OvertimeEntries → Validation settings → User Message
The finish must be after the start and no more than 24 hours later, and the break must be shorter than the shift.

The Validation Settings page with the formula in the Formula box and the message in the User Message box, both outlined in red, the Insert Column list showing BreakMinutes, Color Tag, Compliance Asset Id, Created, DecisionBy, DecisionOn, Department, DepartmentId, EmployeeEmail and EmployeeName, and Save and Cancel buttons

Step 4: Save​

Select Save. SharePoint saves the rule and goes back to List settings.

Check the Rule​

The most common slip with night shifts is leaving the finish on the same day as the start. I filled in a new item that way, 22:00 to 06:00 both on 7 November, and selected Save. SharePoint refused it and showed the message at the top of the form:

The new item form with Error: The finish must be after the start and no more than 24 hours later, and the break must be shorter than the shift outlined in red at the top, and StartTime 07/11/2026 22:00 and EndTime 07/11/2026 06:00 outlined in red

Nothing was saved; the list stayed empty. With EndTime on 8 November, all three conditions are true.

List Validation or Column Validation?​

Column validationList validation
WhereEach column's More options → Column validationList settings → Validation settings
Can useThat column onlyAny of the list's columns that the formula supports
Use it forA rule about one value, such as a formatA rule that compares values

Microsoft's SPList.ValidationFormula reference, written for SharePoint Server 2013, puts it the same way: "the validation formula for a field can refer only to that field, whereas the validation formula for a list item can refer to several or even all fields in the item."

Limits​

  • One list formula. A list has one validation formula, so combine rules with AND.
  • Not every column type. The Insert Column list on this page left out the two Multiple lines of text columns, Reason and ApproverComment.
  • Length. The same Server 2013 reference gives "the maximum length of a validation formula string" as 1024 characters.

Common Mistakes​

MistakeWhat happensDo this instead
Writing the rule as what's wrongValid items are refusedWrite what must be TRUE for a good item
A vague message such as "Invalid data"People can't tell what to fixSay which values are wrong and how
Forgetting that dates subtract to daysComparing with hours gives wrong resultsMultiply by 24 for hours, 1440 for minutes

Troubleshooting​

SymptomLikely causeFix
Your message appears on every saveThe formula is FALSE for valid items tooCheck each condition on its own with a known good item
A night shift is refusedThe finish date is the same as the start datePut the finish on the next day
A column you need isn't in Insert ColumnIt's a type the formula can't use, such as multiple lines of textCompare other columns, or check that value in the app

FAQ​

Do apps and flows have to pass the rule too?​

The rule belongs to the list, and the form showed it as a save error. The Overtime Timesheet app checks the same things before saving, so people see a clear message in the app first.

Can one list have several rules?​

It has one formula, so put every rule inside one AND(…), as the overtime rule does with three conditions. The user message should then cover all of them.

Conclusion​

List settings → Validation settings → a formula that is TRUE for good items, plus a message that says how to fix a bad one → Save. SharePoint then refuses any item that breaks the rule, with your message at the top of the form.

Additional Resources​