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 Automate / Create a flow to check...
Power Automate
Unanswered

Create a flow to check whether a given number is sequential

(0) ShareShare
ReportReport
Posted on by 14
Hi Everyone, I am new to power automate. I need to create a flow to accept a number ex. 12345 or 3245 or 98765 etc. I need to find whether the number is sequential or not, in this case 12345 and 98765 are sequential but 3245 is not.
I have tried using Copilot as we as ChatGPT, but the solutions provided are not helping.
Trying to use a loop but the solutions provided mentions to use Terminate or exit to come out of loop but nothing like this exists in Power automate.
To tackle this again a solution is suggested to use do until loop.
Even trying to increment the counter in loop (like i = i + 1) does not work, in throws error saying the variable (in this case i) cannot be self referenced.
I am stuck here, please let me know if anyone can provide a working solution on how to create this flow.
Categories:
I have the same question (0)
  • SaiRT14 Profile Picture
    1,990 Super User 2025 Season 2 on at
    Create a flow to check whether a given number is sequential
     
    Add a Manually Trigger a Flow trigger with a number input field. 
     
    Use a Compose action to convert the input number to a string if it’s not already a string. - string(triggerOutputs()?['numberInput'])
     
    Initialize Variables: - Create a String variable SequentialCheck and set it to true (initial assumption that the number is sequential). Create a Number variable i and set it to 0 (for iterating through digits).
     
    Create a Loop to Check Digits: Add a Do Until loop: Condition: i >= length(outputs('Compose')) - 1 This ensures the loop stops before the last digit comparison.
    Inside the Do Until loop - Use Compose actions to extract the current digit and the next digit
     
    Current Digit - substring(outputs('Compose'), variables('i'), 1)
    Next Digit - substring(outputs('Compose'), add(variables('i'), 1), 1)
     
    Use a Condition action to check if the difference between the next digit and the current digit is 1: equals(sub(int(NextDigit), int(CurrentDigit)), 1)
     
    If the condition is false: - Set the SequentialCheck variable to false. Add a Terminate action to exit the loop (optional).
     
    Increment Counter: - Add a Set Variable action to increment i by 1 after each iteration - add(variables('i'), 1)
     
    After the loop, add a Condition to check the value of SequentialCheck -  If true, the number is sequential. If false, the number is not sequential.
     
  • MD-19121507-0 Profile Picture
    14 on at
    Create a flow to check whether a given number is sequential
    Thanks from the response but these are the same steps suggested by Copilot and it does not work, there is no straightforward answer to this. There is no terminate or exit clause in power automate.
     
  • Suggested answer
    Ellis Karim Profile Picture
    11,653 Super User 2025 Season 2 on at
    Create a flow to check whether a given number is sequential
     
    You can try the following, but give it a good test:
     
     
    Here are the expressions I used:
     
    Chunk
    =====
    chunk(string(variables('varNumber')),1)
    
    Select
    ======
    From:
    range(0, sub(length(outputs('Chunk')), 1))
    
    Map:
    or(
        equals(
            sub(
                int(outputs('Chunk')?[add(item(), 1)]), 
                int(outputs('Chunk')?[item()])
            ), 
            1
        ), 
        equals(
            sub(
                int(outputs('Chunk')?[add(item(), 1)]), 
                int(outputs('Chunk')?[item()])
            ), 
            -1
        )
    )
    
    
    isSequence variable
    ===================
    not(contains(body('Select'),false))
     
    Map on a single line:
    or(equals(sub(int(outputs('Chunk')?[add(item(),1)]), int(outputs('Chunk')?[item()])), 1), equals(sub(int(outputs('Chunk')?[add(item(),1)]), int(outputs('Chunk')?[item()])), -1))
     
     
    And here is a sample runtime output:


    and another test:



     
    Ellis Karim
     
  • MD-19121507-0 Profile Picture
    14 on at
    Create a flow to check whether a given number is sequential
    Hi @EKarim, thank you for the response, this has greatly helped in the solution, but I would like to add a scenario of palindrome ex. 12321 where it’s not working. 12321 says a sequential number.
    Could you please help me in handling this case.
  • Verified answer
    Ellis Karim Profile Picture
    11,653 Super User 2025 Season 2 on at
    Create a flow to check whether a given number is sequential
     
    In that case, let's try to do the sequence check in two steps, one for ascending (forward) sequence, and another for descending (reverse) sequence. The isSequence variable will be true if the number is in a sequence:
     
     
    The expressions are:
     
    Chunk
    =====
    chunk(string(variables('varNumber')),1)
    
    Select Forward
    ==============
    From: range(0, sub(length(outputs('Chunk')), 1))
    
    Map:
    equals(sub(int(outputs('Chunk')?[add(item(), 1)]), int(outputs('Chunk')?[item()])), 1)
    
    Select Reverse
    ==============
    From: range(0, sub(length(outputs('Chunk')), 1))
    
    Map:
    equals(sub(int(outputs('Chunk')?[add(item(), 1)]), int(outputs('Chunk')?[item()])), -1)
    
    
    isSequence variable
    ===================
    Or(not(contains(body('Select_Forward'),false)), not(contains(body('Select_Reverse'),false)))
     
    Here is the runtime output using 12321:
     
     
    Ellis Karim
     
  • Chriddle Profile Picture
    8,416 Super User 2025 Season 2 on at
    Create a flow to check whether a given number is sequential
    To test this in just one expression, do the following
     

     
    sequential
    • test if the sorted array of digits with removed duplicates equals the original array
    • check if the last digit equals the first digit plus the array length minus 1
    and(
    	equals(
    		sort(
    			union(
    				chunk(string(outputs('Compose')),1),
    				json('[]')
    			)
    		),
    		chunk(string(outputs('Compose')),1)
    	),
    	equals(
    		int(last(chunk(string(outputs('Compose')),1))),
    		add(
    			int(first(chunk(string(outputs('Compose')),1))),
    			sub(length(chunk(string(outputs('Compose')),1)), 1)
    		)
    	)
    )
     
    sequential backwards
    • test if the sorted array of digits reversed with removed duplicates equals the original array
    • check if the last digit equals the first digit minus the array length minus 1
    and(
    	equals(
    		reverse(
    			sort(
    				union(
    					chunk(string(outputs('Compose')),1),
    					json('[]')
    				)
    			)
    		),
    		chunk(string(outputs('Compose')),1)
    	),
    	equals(
    		int(last(chunk(string(outputs('Compose')),1))),
    		sub(
    			int(first(chunk(string(outputs('Compose')),1))),
    			sub(length(chunk(string(outputs('Compose')),1)), 1)
    		)
    	)
    )
     
    palindrome
    • check if the array equals the reversed array
    equals(
    	reverse(
    		chunk(
    			string(outputs('Compose')),
    			1
    		)
    	),
    	chunk(
    		string(outputs('Compose')),
    		1
    	)
    )
     
  • Suggested answer
    MD-19121507-0 Profile Picture
    14 on at
    Create a flow to check whether a given number is sequential
    Hi @EKarim, the updated solution worked. Thank you again, this has sorted by issue.
     
    Thank you @Chriddle for you response as well, but i was exploring the one mentioned above and it has worked out.

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 462 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 456 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard