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

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Increment number witho...
Power Apps
Unanswered

Increment number without duplicating

(1) ShareShare
ReportReport
Posted on by 779
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:
I have the same question (0)
  • mmbr1606 Profile Picture
    14,560 Super User 2025 Season 2 on at
    Increment number without duplicating
    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
    779 on at
    Increment number without duplicating
    Hi @mmbr1606​​​​​​​,
     
    Your expression looks exactly the same as mine.
  • Suggested answer
    mmbr1606 Profile Picture
    14,560 Super User 2025 Season 2 on at
    Increment number without duplicating
    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
    779 on at
    Increment number without duplicating
     
    I am getting the error of "The function 'Text' has some invalid arguments." when using the expression you provided.
  • WarrenBelz Profile Picture
    152,853 Most Valuable Professional on at
    Increment number without duplicating
    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
    779 on at
    Increment number without duplicating
    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
    152,853 Most Valuable Professional on at
    Increment number without duplicating
    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
    779 on at
    Increment number without duplicating
    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
    152,853 Most Valuable Professional on at
    Increment number without duplicating
    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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 757 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 322 Super User 2025 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 209 Super User 2025 Season 2

Last 30 days Overall leaderboard