kriSHna

# Working with Sequence and As function in power apps

Previously when we have to generate a sequence of numbers in power apps we used to write a complex formula implementing ForAll to get the desired result.

Now, this approach has been very simple in power apps with the implementation of sequence function, with this you will be able to generate a sequence of numbers with a single line formula.

**Sequence function in power apps**

The skeleton of the sequence function is as follows

`Sequence(records,start,step)`

**Records** - The number of records to generate using the sequence function consider I want to generate a series of numbers starting from 1 to 10, then I will specify the record value as 10 because we are trying to generate 10 records in the scenario.

**Start** - The value from where you want to start the series generation if I want to start the series generation from 2 then I can specify the value as 2 here. This will indicate the engine that it has to start the sequence generation starting from 2. This is an optional parameter.

**Step** - Use this value to indicate the number of records to skip during the series generation, consider if we have to generate a series of the first 10 even numbers, then we will indicate the step value is 2 because we have to skip 2 values each time a number is generated.

The formula for generating the first 10 even numbers will be as follows

`Sequence(10,2,2)`

**"As" operator in PowerApps **

The as operator in power apps works the same way as in SQL, we can use this to store the parameters in record scope so that we can evaluate the value later in the same formula.

consider we want to write a formula to wherein we generate a sequence of even numbers, and if the value is less than 10 we further multiply it by 2 else we will print the number as it as.

`ForAll(Sequence(10,2,2) As EvenNumbers,If(EvenNumbers.Value < 10,EvenNumbers.Value * 2,EvenNumbers.Value))`

When we use the As operator the value is stored as a record with a specified name, we can then use the name reference in the same formula to fetch the information instead of re-creating the complete formula again.

Please check the below video to see the scenario described in action.

Hope the insights shared have been helpful, please share your feedback by dropping a comment.