Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Outlook
    • Planner
    • Power Apps
    • SharePoint
    • Teams
  • Triggers
  • Ready to use solutions
    • Approval Process Template
    • Task Delegation App
    • The Ultimate Power Automate expressions cheat sheet
    • Power Automate HTTP requests to SharePoint cheat sheet
    • Power Automate HTTP requests to Graph API cheat sheet
  • ABOUT ME
  • Get help with your flow
  • POWER PLATFORM SERVICES
Menu

How to get only the last item from a SharePoint list in Power Automate

Posted on September 19, 2021September 19, 2021 by Tom

“I need to find the last value for an entry in a SharePoint list to increment its id for a new item, how do I recognise the last item with Power Automate?”


In most cases when you use SharePoint list as an information storage, you can utilise the existing item ID. It’ll be unique, it’ll be incremented by 1 for each new item, and you can use it to build more complex IDs. But that’s not true if you store various data in the same SP list. For example, if you store entries from various MS Forms in the same list with unique, custom IDs – Form1_ID, Form2_ID… The default ID will keep incrementing for each item, which would leave gaps in your IDs sequence. The only solution would be to get the last ID in the desired sequence, and increment it. And for this you need to find the item with the last ID.

Get only the last item

To get the last item you’ll need a lookup to the list. But don’t take all the items in the list, that would be more than you need. You need only one specific item. The one that’s part of the desired sequence, and that has the highest id. That’s three things to configure in the ‘Get items’ action.

Take only items from the desired sequence

As already mentioned, you want only items from the same sequence. Configure the ‘Filter Query’ in ‘Get items’ to take only the items where the ID contains or begins with a specific string, e.g.

substringof('Form1', CustomID)     = the column CustomID contains string 'Form1'

or

startswith(CustomID, 'Form1')      = the column CustomID starts with string 'Form1'

Note: CustomID is the internal name of the column with the custom ID.

Sort the returned items from newest to oldest

Since you want the latest item, with the highest id, you should define order of the returned items. ‘Get items’ has a field ‘Order By’ that allows you to do that. The safest way to get the latest item is to use the standard SharePoint ID = the higher the ID, the newer the item. Define the filter to return items in descending order by their ID.

ID desc

Get only the latest items

The ‘Get items’ will return the right items, in the right order, but it’d still return more items than you need. You need only 1 item, the last one. And that’s the last step, configure the ‘Get items’ action to return only 1 item. And since you sorted the result from the newest to the oldest, the 1 returned item will be the newest one.

Power Automate last item SharePoint

The ‘Get items’ action above will do a lookup to the TestList. It’ll search for items whose CustomID column begins with the string ‘Form1’. Once it gets those items, it’ll sort them by ID, and return only the 1 item with the highest ID. You can take the result, extract the ID number, increment it, and create new item with the new ID.

Don’t worry about the ‘Apply to each’ it’ll add, since it’ll return just 1 item, it’ll run only once.

Summary

When you need to get the last item from a SharePoint list in Power Automate, the easiest way is to do it all in the ‘Get items’. The action itself gives you all the tools you need – you can filter the items, order them, and limit how many items it should return.

You can follow the same process also if you want just the last item in general, just skip the ‘Filter Query’ part.


πŸš€ Master Power Automate

Join 2,000+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

πŸš€ Master Power Automate

Join 2,000+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

Still exchanging emails to get things approved?

Use the Approval Process Template and the Task Delegation App to skip the hard part and deploy an automated, fully functional approval solution on a SharePoint list in minutes! And then the next one, and the next one...

Approval Template Preview ✨ Learn more ✨

Turn ideas into flows with ease!

Grab the complete Power Automate Cheat Sheet Bundleβ€”everything you need to master expressions, SharePoint HTTP calls, and Graph API in Power Automate.

Cheat Sheet Bundle Preview ✨ Get the Cheat Sheets

Didn't find what you were looking for?
Need to adjust a solution to fit your needs?
Or would you just like to get an assistance from somebody with thousands of hours of experience with Power Automate?

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2025 Let's POWER Automate | Theme by SuperbThemes