Arrays in Power Apps

A While back I wrote a post about arrays in Power Automate. Today I will look at arrays in Power Apps.

Create an Array

In a Flow you can create an array with the function CreateArray or you can simply use the json syntax to create an array like this:

[
  [
    "Nissan",
    "Red",
    3,
    "01/07/2015"
  ],
  [
    "Citroen",
    "Green",
    2,
    "21/09/2016"
  ],
  [
    "Audi",
    "Blue",
    4,
    "01/07/2014"
  ]
]

In Power Apps you can also create an array with the json. using either Set, or create collection.

With the below example I’ve created an array of number and stored this in my variable Array.

Set(Array,[1,2,3,4,5,6,7,8])
Table/Collection or Array in Power Apps.

As you can see Power Apps calls these Arrays tables or collections but whatever you call them they are list of objects or pieces of data.

Get an item in an Collection or Table

In Flow you can now use array[0] to get to an element in the array, but in Power Apps this will not work as you will get an

Unexpected characters. Characters are used in the formula in an unexpected way.

Get an element in an array

The only way to get to a specific element in your array is by using a combination of the following functions.

If you for example want to get the 3rd item in the array then you could use:

Last(FirstN(Array, 3)).Value

The FirstN function in the above example will get the first 3 items in my array. Then the Last function will take those 3 items and give me the last one of the 3 items.

Hopefully soon Array[3] will be made available as this is one of those small annoyances that make Power Apps hard to learn for so many. And even when you find these kind of workarounds, it will give most of us the feeling “It shouldn’t be necessary to do this!”

Avatar for Pieter Veenstra

By Pieter Veenstra

Business Applications Microsoft MVP working as the Head of Power Platform at Vantage 365. You can contact me using contact@sharepains.com

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from SharePains by Microsoft MVP Pieter Veenstra

Subscribe now to keep reading and get access to the full archive.

Continue reading