Skip to main content

Notifications

Community site session details

Community site session details

Session Id : AgeefYzsxPvuixV4Wmufnv
Power Apps - Building Power Apps
Answered

Auto Incrementing function

Like (0) ShareShare
ReportReport
Posted on 27 Oct 2024 15:08:34 by 61
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.
  • Verified answer
    WarrenBelz Profile Picture
    146,508 Most Valuable Professional on 29 Oct 2024 at 20:32:24
    Auto Incrementing function
    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


  • deepaks1 Profile Picture
    61 on 29 Oct 2024 at 11:54:27
    Auto Incrementing function
    @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.
  • WarrenBelz Profile Picture
    146,508 Most Valuable Professional on 29 Oct 2024 at 01:32:28
    Auto Incrementing function
    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
    61 on 28 Oct 2024 at 11:31:41
    Auto Incrementing function
     
    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
    146,508 Most Valuable Professional on 27 Oct 2024 at 21:09:38
    Auto Incrementing function
    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

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

Thomas Rice – Community Spotlight

We are honored to recognize Thomas Rice as our March 2025 Community…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,508 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,342 Most Valuable Professional

Leaderboard