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 Apps / Auto Incrementing func...
Power Apps
Answered

Auto Incrementing function

(0) ShareShare
ReportReport
Posted on by 63
Dear Experts
 
I'm seeing an issue in generating auto increment numbers in my ID column. I'm using below formula to generate auto numbers (
(ThisItem.id) &
First(Sort('Data base name',id,SortOrder.Descending)).id+1)
 
I've Edit form and gallery connected to each other and sql as data source.
 
For the new record auto number generation is working fine, but when I try to update existing record by clicking the gallery, the id column is not behaving as expected. In the below example if you look at the id column in edit form as "1928" (1 is the existing id record and 928 is the next auto increment number), when I click Item ID 1 to edit, next auto increment number (928) is not disappearing instead it adds to existing id number. See below screen shot. Anyone can give me a solution, please.
Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    154,540 Most Valuable Professional on at
    Is your Id column numeric or text. If a number, 
    1000 +
    First(
      Sort(
      'Data base name',
      id,
      SortOrder.Descending
      )
    ).id + 1
    If text
    ThisItem.id &
    Value(
      First(
      Sort(
      'Data base name',
      id,
      SortOrder.Descending
      )
      ).id
    ) + 1
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)     Visit my blog Practical Power Apps    Buy me a coffee

  • deepaks1 Profile Picture
    63 on at
     
    Hi @WarrenBelz
     
    Thanks for your reply. 
     
    My id column is a numeric column, as you suggested I used: 
    1000 +
    First(
       Sort(
          'Data base name',
          id,
          SortOrder.Descending
       )
    ).id + 1
    the last item id in my source is: 466666, when I clicked "Add new record", id column should have populated 466667 instead it is populating: 467667
    when I clicked an existing item : 917, all column values are populating correctly except id field, id column is not showing the selected value. 
  • WarrenBelz Profile Picture
    154,540 Most Valuable Professional on at
    OK - I am now quite unclear - what exactly are you adding at the start (in your initial post) as it seems you simply need the bottom part of the formula
  • deepaks1 Profile Picture
    63 on at
    @WarrebBlz
    Ok, My id is a number field, I'm looking to auto increment next id number when "Add New record" button is clicked and when an existing record is clicked, id field should display the clicked id# in the edit form. I tried the formula you gave me and it is not displaying correct id# (existing record in gallery). Hope this makes it clear.
  • Verified answer
    WarrenBelz Profile Picture
    154,540 Most Valuable Professional on at
    As I mentioned, you should just need
    First(
       Sort(
          'Data base name',
          id,
          SortOrder.Descending
       )
    ).id + 1
     Your initial post suggested you were adding something to the front, but this does not appear to be the case

    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)     Visit my blog Practical Power Apps    Buy me a coffee


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 Apps

#1
WarrenBelz Profile Picture

WarrenBelz 525 Most Valuable Professional

#2
Haque Profile Picture

Haque 308

#3
Kalathiya Profile Picture

Kalathiya 234 Super User 2026 Season 1

Last 30 days Overall leaderboard