Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

Auto Incrementing function

(0) ShareShare
ReportReport
Posted on 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
    WarrenBelz 145,495 on at
    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
    deepaks1 61 on at
    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
    WarrenBelz 145,495 on at
    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
    deepaks1 61 on at
    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
    WarrenBelz 145,495 on at
    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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

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

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,495

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,822

Leaderboard