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.
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 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.
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:
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 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!”