Blog
SharePoint - Deleting the last record from a SharePoint list - how NOT to do this!
January 18. 2024
If you need to write formula to delete or to remove the last record from a SharePoint, this post describes the pattern that you should follow.
Removing the last record from a SharePoint list should seemingly be easy. So what's the reason for this post?
Why the suggested approach to remove the last record from SharePoint is incorrect
The correct way to delete the last record from a SharePoint list
The reason is to correct some misunderstanding that I'm seeing, particularly due to the prevalence of AI-generated answers.
To give an example, here's a solution that Bing generates for this question.
Here's a forum post that suggests the same pattern.
The remainder of this post describes why you should avoid the pattern that's shown above, and describes the correct approach to delete the last record from a SharePoint list.
Why the suggested approach to remove the last record from SharePoint is incorrect
The footnote from Bing chat summarises why this approach isn't ideal. It statesĀ "Please note that this will only work if the SharePoint list has less than 500 rows"
SharePoint lists commonly exceed 500 rows so to futureproof an app, it's important to choose formula that supports more than 500 rows. As a point of clarification, the 500 value refers to the "data row limit" value in an app's settings. We can increase this to a maximum of 2000.
The correct way to delete the last record from a SharePoint list
The incorrect formula to delete the last record selects the last record by calling Last or LastN. With the "data row limit" set to the default value of 500, this will return the 500th record when the size of the SharePoint list exceeds 500.
Therefore, the correct approach is to retrieve the last record by selecting the First record of the SharePoint list sorted in Descending sequence.
Therefore, the correct formula to remove the last record from a SharePoint list looks like this. This formula will work correctly whatever the size of the SharePoint list.
Remove(
YourSharePointList,
First(
Sort(
YourSharePointList,
ID,
SortOrder.Descending
)
)
)
Conclusion
If you want to delete the last record from a SharePoint list, this post describes the correct way to tackle this task when working with SharePoint lists with more than 500/2000 rows.
- Categories:
- SharePoint
Related posts
- Walkthrough - An beginners guide to building an app that stores images in SharePoint
- SharePoint - What to do when there's a mismatch between times in Power Apps and SharePoint
- SharePoint - Filtering lists by User() is now delegable
- SharePoint - How to fix the "skip to main content" error message on integrated forms, or to fix forms where records don't save
- SharePoint - Use this trick to perform a 'contains' type search in a more delegable way
- Sharepoint - Filtering records by yes/no columns bug - now fixed!
- Configuration - How to set the SharePoint address of a data source with a variable
- Data - How to make a copy of a record
- SharePoint - How to export and import lists and maintain lookup relationships
- SharePoint - how to fix list threshold errors when working with very large lists
- Data - How to move SharePoint sites, lists, and data
- Code - Can we hack SharePoint ID columns to be delegable using the greater than/less than operators?
- SharePoint - How to filter records by the current user
- SharePoint - Beware of numeric calculated columns!