Removing the last record from a SharePoint list should seemingly be easy. So what's the reason for this post?
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.
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.