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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Need help in increment...
Power Automate
Suggested Answer

Need help in incrementing number

(1) ShareShare
ReportReport
Posted on by 4
Hi All, i have a scenario in power automate desktop. I'm working in a process where i need to increment the value for that record.
 
Scenario:1
 
Ex : A09 or A23
 
I need output like A10 or A24 after incrementing 
 
Scenario:2
 
Ex : A99
 
I need output like B01
 
If it reaches 99 then it should go to next alphabet
 
 
Can anyone help me how to achieve these scenarios using power automate desktop 
 
 
I have the same question (0)
  • MichaelFP Profile Picture
    1,847 Super User 2025 Season 2 on at
    This information is saved in Dataverse? I think we need more clarification what are you doing to help with that. Based on you wrote there  is many ways to achivie that.
  • CU31071656-2 Profile Picture
    4 on at
    Hi @MichaelFP
     
    I'm getting that value from a database query 
    I'm using this in power automate desktop 
     
    If value is A09 then i need to make it as A10
     
    Similarly if it's A99 i need to make it as B01
  • Suggested answer
    NathanAlvares24 Profile Picture
    1,714 Moderator on at
     
    Scripting is more simpler way to achieve this. Use the below for reference.
    My flow:
     
    Since you are retrieving the data from the database using queries and I believe you have already achieved that. So, I have provided 2 scripts below: 1st one using VB Script and 2nd one using Python.
     
    1) VB Script code:
     
    ' Input from PAD variable
    Dim input
    input = "%InputVariable%"
    
    ' Prepare to store results
    Dim resultList
    resultList = ""
    
    ' Determine the separator based on the presence of "or" or "and"
    Dim separator
    If InStr(input, " or ") > 0 Then
        separator = " or "
    ElseIf InStr(input, " and ") > 0 Then
        separator = " and "
    Else
        separator = " " ' Default to space if no separator is found
    End If
    
    ' Split the input into individual items
    Dim items
    items = Split(input, separator)
    
    ' Process each item
    Dim i, alphabet, number, numberValue, result
    For i = 0 To UBound(items)
        ' Remove any leading/trailing spaces from the item
        items(i) = Trim(items(i))
        
        ' Extract the alphabet and numeric part
        alphabet = Left(items(i), 1)
        number = Mid(items(i), 2, 2)
        
        ' Convert numeric part to an integer
        numberValue = CInt(number)
        
        ' Check if number is 99
        If numberValue = 99 Then
            ' Increment the alphabet and reset number to 01
            alphabet = Chr(Asc(alphabet) + 1)
            result = alphabet & "01"
        Else
            ' Increment the number
            numberValue = numberValue + 1
            ' Format number with leading zero if necessary
            If numberValue < 10 Then
                number = "0" & numberValue
            Else
                number = CStr(numberValue)
            End If
            result = alphabet & number
        End If
        
        ' Add the result to the list
        If resultList <> "" Then
            resultList = resultList & separator & result
        Else
            resultList = result
        End If
    Next
    
    ' Output the result list to PAD
    WScript.StdOut.Write resultList
     
    2) Python code:
     
    # Get the input from PAD variable
    input_string = """%InputVariable%"""
    
    def increment_value(input_string):
        # Determine the separator based on the presence of "or" or "and"
        if " or " in input_string:
            separator = " or "
        elif " and " in input_string:
            separator = " and "
        else:
            separator = " "  # Default to space if no separator is found
    
        # Split the input into individual items
        items = input_string.split(separator)
        results = []
    
        for item in items:
            item = item.strip()  # Remove any leading/trailing spaces
    
            # Extract the alphabet and numeric part
            alphabet = item[0]
            number = item[1:]
    
            # Convert numeric part to an integer
            number_value = int(number)
    
            # Check if number is 99
            if number_value == 99:
                # Increment the alphabet and reset number to 01
                alphabet = chr(ord(alphabet) + 1)
                result = f"{alphabet}01"
            else:
                # Increment the number
                number_value += 1
                # Format number with leading zero if necessary
                result = f"{alphabet}{number_value:02}"
    
            results.append(result)
    
        # Join results using the same separator
        return separator.join(results)
    
    # Call the function and get the output
    output_value = increment_value(input_string)
    
    # Return the result back to PAD
    print(output_value)
     
    1st try:
    Input:
     
     
    Output:

     
     
    2nd try:
    Input:
     
     
    Output:

     
     
     
    3rd try:
    Input:
     
     
    Output:

     
    I hope this helps.
     
    Regards,
    Nathan Alvares
  • Suggested answer
    Chinmay_Dhabal Profile Picture
    10 on at
    I have seen @NathanAlvares24   has used VBScript and Python to solve this problem .
    Here i have not used any scripting language to solve the problem .
     You can copy paste the below code in PAD and see how it works , any suggestions warmly welcome :D 


    SET vCurrentString TO $'''P99'''
    Text.GetSubtext.GetSubtext Text: vCurrentString CharacterPosition: 0 NumberOfChars: 1 Subtext=> vCharacter
    Text.GetSubtext.GetSubtextFrom Text: vCurrentString CharacterPosition: 1 Subtext=> vNumber
    SET vNumber TO vNumber + 1
    IF vNumber < 10 THEN
        SET vNumber TO $'''0%vNumber%'''
    ELSE IF vNumber > 99 THEN
        Variables.CreateNewDatatable InputTable: { ^['Column1'], [$'''A'''], [$'''B'''], [$'''C'''], [$'''D'''], [$'''E'''], [$'''F'''], [$'''G'''], [$'''H'''], [$'''I'''], [$'''J'''], [$'''K'''], [$'''L'''], [$'''M'''], [$'''N'''], [$'''O'''], [$'''P'''], [$'''Q'''], [$'''R'''], [$'''S'''], [$'''T'''], [$'''U'''], [$'''V'''], [$'''W'''], [$'''X'''], [$'''Y'''], [$'''Z'''] } DataTable=> DataTable
        Variables.FindOrReplaceInDataTable.FindItemInDataTableEverywhere DataTable: DataTable AllMatches: True ValueToFind: vCharacter MatchCase: False MatchEntireCellContents: False DataTableMatches=> DataTableMatches
        SET vNextIndex TO DataTableMatches[0][0]
        SET vNextIndex TO vNextIndex + 1
        SET vCharacter TO DataTable[vNextIndex][0]
        SET vNumber TO $'''01'''
    END
    SET vOutputString TO $'''%vCharacter%%vNumber%'''




     
  • Riyaz_riz11 Profile Picture
    3,891 Super User 2025 Season 2 on at
    Hi,
    Find the below code,
    it contains both scenarios.
     
    SET NewVar TO ['A', 'B', 'C', 'D']
    LOOP FOREACH CurrentItem3 IN NewVar
        LOOP LoopIndex FROM 1 TO 15 STEP 1
            Text.ParseText.RegexParse Text: LoopIndex TextToFind: $'''\\d''' StartingPosition: 0 IgnoreCase: True OccurrencePositions=> Positions Matches=> Matches
            SET NewVar2 TO $'''%CurrentItem3%%LoopIndex%'''
            IF Matches.Count = 1 THEN
                SET NewVar2 TO $'''%CurrentItem3%0%LoopIndex%'''
            END
        END
    END
     
     
     
     
    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.
    Regards,
    Riyaz
     
     
     
  • Suggested answer
    WillSG Profile Picture
    352 Moderator on at
    Hi @CU31071656-2 I hope you are doing well.
     
    I believe that others have provided really great and awesome ways to overcome this issue. However, I'd like to share a different approach, so you can keep it in consideration for your future challenges.

    Based on your needs, this can be achieved using some If actions and a robust logic to accomplish the results on those scenarios, please review the sniped code below and adjust it as needed.

    See the sniped Code below:


    SET ValueToBeIncreased TO $'''A99'''
    Text.GetSubtext.GetSubtextFrom Text: ValueToBeIncreased CharacterPosition: 1 Subtext=> Subtext
    Text.Replace Text: ValueToBeIncreased TextToFind: Subtext IsRegEx: False IgnoreCase: False ReplaceWith: $'''%''%''' ActivateEscapeSequences: False Result=> VariableLetter
    IF Subtext = 99 THEN
        SET Subtext TO $'''01'''
        SET LetterList TO $'''A
    B
    C
    D
    E
    F
    G
    H
    I'''
        Text.SplitText.Split Text: LetterList StandardDelimiter: Text.StandardDelimiter.NewLine DelimiterTimes: 1 Result=> TextList
        LOOP FOREACH CurrentItem IN TextList
            IF CurrentItem = VariableLetter THEN
                SET NextLetterFound TO $'''YES'''
            ELSE
                IF Contains(NextLetterFound, $'''YES''', True) THEN
                    SET NextLetterFound TO $'''None'''
                    SET VariableLetter TO CurrentItem
                    EXIT LOOP
                END
            END
        END
    ELSE
        Variables.IncreaseVariable Value: Subtext IncrementValue: 1
    END
    SET FinalValue TO $'''%VariableLetter%%Subtext%'''
    Display.ShowMessageDialog.ShowMessage Title: $'''YOU ROCK!''' Message: FinalValue Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: True ButtonPressed=> ButtonPressed



    Please let me know if it works, happy automating!

    If I have addressed your inquiry successfully, kindly consider marking my response as the preferred solution. If you found my assistance helpful, a 'Thumbs Up' would be greatly appreciated.
     
    Additionally, I offer specialized consultancy and development services leveraging PAD. If you're interested in exploring these services further, feel free to DM me, and we can initiate a discussion.

    Finally, here is my YOUTUBE CHANNEL please subscribe to my channel and connect with me on LinkedIn Profile.

    Kind regards,
     
    Will SG
    Founder & Director
    RAMSolutions
    www.ramscr.com

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 Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 525 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 324 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard