cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
wiredup
Helper I
Helper I

PA limitation or I don't understand: arrays

Dear PA community,

 

Back in my programming days, I was able to create a "blank" array and access that array directly write to it via an index.

 

Is it possible for me to do the same in PA and how would I go about accessing the array without using the Apply to Each function?

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
fchopo
Super User
Super User

Hello @wiredup 

Where does this data come from? Excel? SharePoint?

Regards,

Ferran

Did I answer your question? Please consider to mark my post as a solution to help others.
Proud to be a Flownaut!

View solution in original post

7 REPLIES 7
Paulie78
Super User
Super User

You cannot easily dimension an array to a particular size (but you can do it). But you can easily access arrays via index.

 

For example, if I create a compose action and put this into it:

[ "Paul", "John", "Ringo", "George" ]

I can directly access the third element with this code:

outputs('Compose')[2]

The index number is 2 for the 3rd element because the array numbering starts from zero. So you can directly read via an index, but you cannot directly write to an index.

 

You can use the range expression to initialize an array of numbers and use that to create an array of objects. Using the example above you can do something like this:

2021-04-15_13-59-20.png

This produces an array that is like this:

{
    "body": [
        {
            "Index": 0,
            "Name": "Paul"
        },
        {
            "Index": 1,
            "Name": "John"
        },
        {
            "Index": 2,
            "Name": "Ringo"
        },
        {
            "Index": 3,
            "Name": "George"
        },
        {
            "Index": 4,
            "Name": null
        },
        {
            "Index": 5,
            "Name": null
        },
        {
            "Index": 6,
            "Name": null
        },
        {
            "Index": 7,
            "Name": null
        },
        {
            "Index": 8,
            "Name": null
        },
        {
            "Index": 9,
            "Name": null
        },
        {
            "Index": 10,
            "Name": null
        }
] (and so on)

 

Does that help at all?

fchopo
Super User
Super User

Hello @wiredup 

Have a look at the following sample:

array.png

You can read any item in the array using an expression like variables('your_array')[position] starting from 0 (in this example the result would be "item3").

Hope it helps!

Ferran

Did I answer your question? Please consider to mark my post as a solution to help others.
Proud to be a Flownaut!

Thank you both @fchopo @Paulie78 for your reply. I know @Paulie78 you have replied to the previous posts.

 

Basically, I am trying to loop thru each of these and accumulate their total sales: (ID3 & ID5).  As you can see I could have 1 location listed once or listed multiple times depending on when (day) they sold the item.

 

Thus, I was thinking I'd use an array to store TOTALS for each location ONLY.  I'd assign an index to each location (e.g., 1 for Dumfries and 2 for Fredericksburg) ... then, as sales came in via a loop, I'd just add to an existing total in an array configuration.

 

Maybe I'm doing this wrong?  In a different approach, I used a loop with previous/current location to write records but it's been tough as some locations have 1 row while others may have 3.

 

wiredup_0-1618530260344.png

 

fchopo
Super User
Super User

Hello @wiredup 

Where does this data come from? Excel? SharePoint?

Regards,

Ferran

Did I answer your question? Please consider to mark my post as a solution to help others.
Proud to be a Flownaut!

View solution in original post

Excel csv 

fchopo
Super User
Super User

Hi @wiredup 

First of all, I would try to Group BY Location, and after that, apply for each item in the group by a sum of the elements. 

You could get an idea from here: Do Group By in Microsoft Flow with two simple elegant loops — John Liu .NET

Hope it helps!

Ferran

Did I answer your question? Please consider to mark my post as a solution to help others.
Proud to be a Flownaut!
drfixer
Helper I
Helper I

@fchopo!

This is EXACTLY what I was looking for... thank you!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (2,476)