Sorting data in a Lookup column in SharePoint can be a bit tricky because unlike text, number, or date columns, the data in a lookup column is actually a reference to data in another list. SharePoint treats lookup columns differently, which can cause sorting issues. However, there are a few methods you can use to sort data in a lookup column in SharePoint.
Methods to Sort Lookup Columns in SharePoint:
- Sort Based on the Lookup Value (Default Sorting in Views)
Navigate to the list: Go to the list where you have the lookup column. Create or Modify a View: Go to the list settings and either create a new view or modify an existing view. In the Sort section of the view settings, you should see the lookup column listed. Choose the Lookup Column: Select the lookup column you want to sort by. SharePoint will sort based on the lookup values (the displayed value in the lookup column), just like how it sorts text columns.
Limitations: This only works if you’re sorting based on the displayed value (like the Title field in the related list). If you’re trying to sort based on other columns in the lookup list (e.g., a number or date field in the referenced list), this method won’t work directly.
- Use Calculated Columns
If you need to sort based on another field in the lookup list, you can create a calculated column in the main list:
Create a Calculated Column in the list where the lookup column exists.
Use a formula to bring in the lookup value (text or number) from the lookup list and convert it to a sortable format.
Then, sort the calculated column in the view settings.
Example: If you want to sort based on a number from the referenced list, you can create a calculated column that displays that number and then sort by the calculated column.
- Use JavaScript or Power Automate for Complex Sorting
If you need more advanced sorting or sorting based on a field that isn’t directly visible in the lookup (e.g., sorting based on a secondary field in the related list), you can:
Use JavaScript (JSLink or SPFx) to create a custom view that sorts based on complex logic involving the lookup field.
Use Power Automate (Flow) to pull the lookup field data, sort it, and update a helper field that can be used to display and sort the data.
These methods require a bit of customization and coding knowledge, but they offer flexibility for advanced sorting scenarios.
- Sort by the Lookup Source List
If sorting the lookup data itself is important (for example, when the list you’re looking up to has its own sorting needs), you can:
Go to the source list (the list being looked up) and ensure that it is sorted in the desired order.
This doesn’t directly affect how the lookup column in the main list is sorted, but it helps ensure that the data shown in lookup controls (e.g., in forms or dropdowns) is sorted properly.
- Group By and Sorting in Modern SharePoint Views
In the modern SharePoint experience, you can combine sorting and grouping:
Group By the lookup column in a view, and then sort the group headers based on another column (e.g., date or number).
This gives a visually appealing way to display sorted data, even if the sorting is indirectly tied to the lookup column.
Limitations of Sorting Lookup Columns:
Sorting by a secondary field in the lookup list: SharePoint does not allow sorting directly by a field that is not displayed in the lookup column.
Performance: Sorting lookup columns can sometimes impact performance, especially if the lookup list contains a large number of records.
Workaround Summary:
For basic sorting by the displayed value, use the Sort options in the View settings.
For more complex sorting, you may need to use calculated columns, Power Automate, or JavaScript customizations.
I hope this helps! If my answer is helpful to you, you can adopt it, thank you!