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 / Increment number witho...
Power Apps
Suggested Answer

Increment number without duplicating

(1) ShareShare
ReportReport
Posted on by 789
Hello,
 
I am trying to create an expression to generate incremented text numbers from a ComboBox that is connected to a Dataverse Choice column, without creating duplicate text numbers.
 
I was using this expression below:
 
DataCardValue7.Selected.Name & Mod(Year(Today()), 100) & "-" & 
   If(
      IsBlank(
         Max(
            Filter(
               Table,
               StartsWith(Column, DataCardValue7.Selected.Name & Mod(Year(Today()), 100) & "-")
            ),
            Value(Mid(Column, Len(DataCardValue7.Selected.Name & Mod(Year(Today()), 100) & "-") + 1, Len(TrialCode)))
         )
      ),
      1,
      Max(
         Filter(
            Table,
            StartsWith(Column, DataCardValue7.Selected.Name & Mod(Year(Today()), 100) & "-")
         ),
         Value(Mid(Column, Len(DataCardValue7.Selected.Name & Mod(Year(Today()), 100) & "-") + 1, Len(TrialCode)))
      ) + 1
   )
 
 
Below is the values of the ComboBox.
 
["Dave", "Joe", "John", "Emily", "James", "Joe"]
 
 
Below is the example of the output I am trying to achieve.
Example :
 
Dave25-1
Joe25-2
John25-3
John25-4
Emily25-5
James25-6
Joe25-7
Categories:
  • mmbr1606 Profile Picture
    14,629 Super User 2026 Season 1 on at
    hey
     
     
    can u give this a try:
    DataCardValue7.Selected.Name & 
        Mod(Year(Today()), 100) & 
        "-" & 
        If(
            IsBlank(
                Max(
                    Filter(
                        Table,
                        StartsWith(Column, DataCardValue7.Selected.Name & Mod(Year(Today()), 100) & "-")
                    ),
                    Value(Mid(Column, Len(DataCardValue7.Selected.Name & Mod(Year(Today()), 100) & "-") + 1, Len(Column)))
                )
            ),
            1,
            Max(
                Filter(
                    Table,
                    StartsWith(Column, DataCardValue7.Selected.Name & Mod(Year(Today()), 100) & "-")
                ),
                Value(Mid(Column, Len(DataCardValue7.Selected.Name & Mod(Year(Today()), 100) & "-") + 1, Len(Column)))
            ) + 1
        )
    
    if it helped please mark as verified answer
     
     
    cheers
  • Caleb62881177 Profile Picture
    789 on at
    Hi @mmbr1606​​​​​​​,
     
    Your expression looks exactly the same as mine.
  • Suggested answer
    mmbr1606 Profile Picture
    14,629 Super User 2026 Season 1 on at
    hey
     
    sorry copy/paste error
     
    pls try this:
    DataCardValue7.Selected.Name & 
        Text(Year(Today()) Mod 100) & 
        "-" & 
        (
            Max(
                ForAll(
                    Filter(
                        Table,
                        StartsWith(Column, DataCardValue7.Selected.Name & Text(Year(Today()) Mod 100) & "-")
                    ),
                    Value(Mid(Column, Len(DataCardValue7.Selected.Name & Text(Year(Today()) Mod 100) & "-") + 1, Len(Column)))
                )
            ) + 1
        )
    )
    
    cheers
  • Caleb62881177 Profile Picture
    789 on at
     
    I am getting the error of "The function 'Text' has some invalid arguments." when using the expression you provided.
  • WarrenBelz Profile Picture
    156,774 Most Valuable Professional on at
    Just adding some input here, mainly to get rid of all that duplicated code. One other comment is your reference to column in the text part of the formula does not refer to a specific record.
    With(
       {
          _Year: Mod(Year(Today()), 100) & "-",
          _Name: DataCardValue7.Selected.Name
       },
       With(
          {
             _Table:
             Filter(
                Table,
                StartsWith(
                   Column, 
                   _Name & _Year
                )
             )
          },
          _Name & _Year & 
          If(
             CountRows(_Table) = 0,
             Value(
                Mid(
                   Column, 
                   Len(_Name & _Year) + 1, 
                   Len(TrialCode)
                )
             ),
             1,
             Max(
                _Table,
                Value(
                   Mid(
                      Column, 
                      Len(_Name & _Year) + 1, 
                      Len(TrialCode)
                   )
                ) + 1
             )
          )
       )
    )
  • Caleb62881177 Profile Picture
    789 on at
    Hi @WarrenBelz, Sorry for responding now.
     
     
    This is my original formula 
    DataCardValue7.Selected.Name & Mod(Year(Today()), 100) & "-" & 
       If(
          IsBlank(
             Max(
                Filter(
                   'AGTRS Trial Request Tables',
                   StartsWith(TrialCode, DataCardValue7.Selected.Name & Mod(Year(Today()), 100) & "-")
                ),
                Value(Mid(TrialCode, Len(DataCardValue7.Selected.Name & Mod(Year(Today()), 100) & "-") + 1, Len(TrialCode)))
             )
          ),
          1,
          Max(
             Filter(
                'AGTRS Trial Request Tables',
                StartsWith(TrialCode, DataCardValue7.Selected.Name & Mod(Year(Today()), 100) & "-")
             ),
             Value(Mid(TrialCode, Len(DataCardValue7.Selected.Name & Mod(Year(Today()), 100) & "-") + 1, Len(TrialCode)))
          ) + 1
       )
     
    I am getting this error with the formula you have provided.
    Invalid number of arguments: received 3, expected 2.
     
    With(
       {
          _Year: Mod(Year(Today()), 100) & "-",
          _Name: DataCardValue7.Selected.Name
       },
       With(
          {
             _Table:
             Filter(
                'AGTRS Trial Request Tables',
                StartsWith(TrialCode, 
                   _Name & _Year,
                )
             )
          },
          _Name & _Year & 
          If(
             CountRows(_Table) = 0
             Value(
                Mid(
                   TrialCode, 
                   Len(_Name & _Year) + 1, 
                   Len(TrialCode)
                )
             ),
             1,
             Max(
                _Table,
                Value(
                   Mid(
                      TrialCode, 
                      Len(_Name & _Year) + 1, 
                      Len(TrialCode)
                   )
                ) + 1
             )
          )
       )
    )
    I hope that helps
     
  • WarrenBelz Profile Picture
    156,774 Most Valuable Professional on at
    Try this structure
    With(
       {
          _Year: 
          Mod(
             Year(Today()),
             100
          ) & "-",
          _Name: DataCardValue7.Selected.Name
       },
       With(
          {
             _Code: 
             Filter(
                'AGTRS Trial Request Tables',
                StartsWith(
                   TrialCode,
                   _Name & _Year
                )
             )
          },
          _Name & _Year & 
          With(
             {
                _Max: 
                Max(
                   _Code,
                   Value(
                      Mid(
                         TrialCode,
                         Len(_Name & _Year) + 1,
                         Len(TrialCode)
                      )
                   )
                )
             },
             If(
                IsBlank(_Max),
                1,
                _Max + 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    LinkedIn    Buy me a coffee

     
  • Caleb62881177 Profile Picture
    789 on at
    Hi @WarrenBelz, Thank you for your response.

    The number doesn’t increment unless the value before the "-" is already present in Dataverse.
     
    For example:
     
    ["Dave", "Joe", "John", "Emily", "James", "Joe"]
     
    I get this
     
    Dave25-1
    Joe25-1
    John25-1
    John25-2
    Emily25-1
    James25-1
    Joe25-2
     
    Instead of that
     
    Dave25-1
    Joe25-2
    John25-3
    John25-4
    Emily25-5
    James25-6
    Joe25-7
     
    I hope this gives more clarity
  • WarrenBelz Profile Picture
    156,774 Most Valuable Professional on at
    I would need to build a model, which I cannot do presently - @mmbr1606 might want to have a go at this.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 345 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 225

#3
M Bilal Khan Profile Picture

M Bilal Khan 192

Last 30 days Overall leaderboard