Canvas Apps Expressions

X – Create X records in a collection using Sequence

Accepting a number from users
Accepting a number from users

Introduction

Sequence is a very interesting function that was introduced not too long ago. Using galleries as editable grids has become a common pattern in Power Apps. This is mainly because there isn't another control that can do that, like in model-driven apps. The steps to achieve such functionality, at a high level, are:

  • Create a collection of records
  • Use this as the Items property of a gallery
  • Use a button to add a record to the collection
  • Update existing records and create new records using a button

With these steps, you can add one record at a time. What if you want to accept a number from users to add multiple records at a time? Because why not, its all about user experience and less clicks! Sequence function to the rescue!

Tip - Sequence function!

In one of my earlier blogs (here), I had suggested creating a temporary collection of numbers using the following expression:

ClearCollect(colNumbers,["1","2","3","4","5","6","7","8","9","10",...,"98","99","100",...])

You can then use the following expression to add multiple records:

ForAll(FirstN(colNumbers,Value(txtUserInput.Text)), Collect(colAccounts, "New account"))

Adding multiple records is now much simpler. You can do that without using the temporary number collection by using the Sequence function. Here is the simplified expression:

ForAll(Sequence(Value(txtUserInput.Text)), Collect(colAccounts, "New account"))

To illustrate this, here is a quick demo:

Sequence function in Power Apps
Sequence function in Power Apps

I modified the expression slightly to add one record by default if there is no input from the user:

If(IsBlank(txtUserInput.Text), Collect(colAccounts, "New account"), ForAll(Sequence(Value(txtUserInput.Text)), Collect(colAccounts, "New account")))

Sequence function can be used for many more purposes - how about a separate blog on that?

For the list of all Power Apps formulas, click here.

Stay tuned for the remaining 2 tips!

Related articles

  1. A-Z: 26 tips! Learn how to improve your Power Apps!
  2. Add Picture vs Camera Control – Who is the winner?
  3. Background images for Power Apps screens – the right way!
  4. Combo box or Dropdown? - Who is the winner?
  5. Delegation in Power Apps – How to identify and test!
  6. Edit vs Display – Which is the better form?
  7. Formulas – How to learn the 170+ Power Apps formulas?
  8. Galleries vs Data Tables – How to pick between the two in Power Apps?
  9. Hyperlinks – How to launch web pages & apps in Power Apps!
  10. Icons – How to increase performance!
  11. Jump start – How to speed up Power Apps dev with components!
  12. Keyboard – How to control the keyboard type on mobile
  13. LastSubmit – How to fetch the last submitted record in Power Apps
  14. Media controls in Power Apps – How to improve user experience!
  15. New screens – How to speed up Power Apps dev using templates!
  16. OnStart – How to optimize app loading experience!
  17. Phone camera – How to switch cameras on Power Apps mobile!
  18. Quotes – Should you use single or double in Power Apps?
  19. Reset – How to reset a Power Apps gallery?
  20. SaveData – How to persist your Power Apps sessions!
  21. Tables – How to create tables in Power Apps
  22. User – How to fetch current user’s details in Power Apps
  23. Variables – What happens when global & context var have the same name?
  24. Wrap Count – How to change the layout of Power Apps galleries

3 thoughts on “X – Create X records in a collection using Sequence”

  1. Hi, If you write a blog to help or share information with another, please write and define clearly. Don’t think everyone have same knowledge as you. If the people visit your blog they want learn and take something with them.
    Sorry for the hard comment but I just want to give you info.

Leave a Reply