web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Retrieve last record I...
Power Automate
Answered

Retrieve last record ID from SharePoint list

(0) ShareShare
ReportReport
Posted on by 347

Good morning,

I have a test flow where I want to just retrieve the last record ID within the list. In theory, what I want is to find the last item and then the first item in the list, divide all of that by 4000 to find how many iterations I need to loop, and finally delete every single record from there, but let's take a step back and figure out my first problem.

I have a variable that I'm initliazing and within the array, I want to return the first ID with this code but it's currently not working:

Body('Get_items')[0]?['value']?['ID']


here's my current setup:
get_last_ID.png

 

And here's the error that I'm receiving:
error.png

 

Any ideas on how to fix this?

Categories:
I have the same question (0)
  • ScottShearer Profile Picture
    25,280 Most Valuable Professional on at

    @hnguy71 

    As I understand it, your first goal is to find out how many items are in the list.  Here is an alternate approach:

    ListCount.jpg

     

    The variable holds the total number of list items.

    Remember to go to settings for the Get Items action and set pagination on and set the threshold to a max of 5000 unless you have a P2 license.

     

    If you will be using a do until loop when you delete the items, remember to click "change limits" in the loop and set the count to a number tat makes sense - the default maximum loop limit is 60.

     

     

  • hnguy71 Profile Picture
    347 on at

    Hi @ScottShearer ,

    that only gives me back a maximum number of 5000. I was able to accomplish this in a different way. I used an apply_to_each and since I only have 1 item, I'll set the last record variable to just that 1 ID.
    apply_to_each.png

     

    From there I set a variable to see how many iterations I need to purge the entire list:

    add(div(variables('_LastRecord'), 4000), 1)

    iterations.png

     

    And I'll likely create an array to loop through them but I got further than I expected. I don't have a large list to try this out on but haha so far it looks like it's working. Thanks for the help!

  • Verified answer
    v-bacao-msft Profile Picture
    Microsoft Employee on at

    Hi @hnguy71 ,

     

    I noticed that the expression you used seems to be incorrect.

    Please try to get the last item using the expression below.

    body('Get_items')?['value'][0]['ID']

    37.PNG

    Please try again.

     

    Best Regards,

  • hnguy71 Profile Picture
    347 on at

    Ahhh! The [0] was in the wrong place! Thanks for the help!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 58

#2
David_MA Profile Picture

David_MA 53 Super User 2026 Season 1

#3
Expiscornovus Profile Picture

Expiscornovus 36 Most Valuable Professional

Last 30 days Overall leaderboard