Here I am back with another blog on Power Apps and this time I shall discuss about one of the simplest requirements. Get an item at specific position inside a collection in Power Apps.
If I take this question to anyone exposed to basic programming, the answer shall be – “I would get it by index”. For example if I have a collection (commonly known as array or list) named DemoCollection, I would access the nth item of the array using the below syntax.
var item = DemoCollection[n-1]
You might be wondering, why this blog? Well surprisingly in Power Apps, extremely complex things are so easy to do and sometimes the simplest of things require a workaround. And one such scenario is this one.
Unfortunately we can’t access item at specific position of collection using indexers. However you can do that with a little workaround.
I have a collection as below.
If I want to access the 3rd item in the collection, below is the formula for the same.
Last(FirstN(DemoCollection, 3)).Value
If I make the formula generic, it would be more like the one below. Here n is the position of the item I want to retrieve.
Last(FirstN(DemoCollection, n)).Value
Hope this helped!
You might also like the below posts
Debajit Dutta
Business Solutions MVP
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.