cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JamesM
Level 8

Create a gallery from more than one set of comma delimited string

I am returning three sets of comma delimited strings from Microsoft Flow to PowerApps. I can't return an array or complex object because of the nature of the Respond to PowerApps function. Let's say my three strings like like this: 

 

australia, germany, usa, new zealand

440,308,349,299

one,two,three,four

 

Each set of strings will always have the same amount of values in them, so 4, 4 and 4. Is there any way to somehow combine these together to bind to a Gallery? So I can have. 

 

Gallery Item 1: 

- Australia 

- 440

- one 

 

Gallery Item 2: 

- Germany

- 308

- two

 

and so on? I'm hoping there is. (This is all from tryng to get nested XML elements back from Flow to PowerApps in order to build a set of on-screen elements based on the info). 

1 ACCEPTED SOLUTION

Accepted Solutions
PowerApps Staff Mr-Dang-MSFT
PowerApps Staff

Re: Create a gallery from more than one set of comma delimited string

O I love problems like this!

 

Big idea here is that every nth record lines up among the 3 tables--knowing this is going to help us.

 

There is no way to unite them out of the box. You'll need to bring them together with a repeated action. And when I think of repeated actions, I think of ForAll().

 

Below is the formula I'm suggesting:

 

Clear(joint_collection);

ForAll(any_table,
    Collect(joint_collection,
        {
            column1: Last(FirstN(Split(string1,","),CountRows(joint_collection)+1)).Result,
            column2: Last(FirstN(Split(string2,","),CountRows(joint_collection)+1)).Result,
            column3: Last(FirstN(Split(string3,","),CountRows(joint_collection)+1)).Result...
        }
    )
)

 

 

Let's take this apart.

  • string1, string2, string3 are the strings that are returned from your flow (offers.__)
  • joint_collection is the collection that you want to result by bringing together the respective field from each string
  • any_table could be any one of the split strings since it's just used for determining how many times to loop/repeat the actions, ex: Split(offers.___,",")

 

 

Clear(joint_collection);

ForAll(any_table,
    Collect(joint_collection,
        {
            column1: Last(FirstN(Split(string1,","),CountRows(joint_collection)+1)).Result,
            column2: Last(FirstN(Split(string2,","),CountRows(joint_collection)+1)).Result,
            column3: Last(FirstN(Split(string3,","),CountRows(joint_collection)+1)).Result...
        }
    )
)
  • Red: you already know this part. It's splitting up each string returned from flow.
  • Blue: each time these actions run, one more record is added to the join_collection.

    So this is getting the first n number of records from the split up strings as a table (FirstN). Last() picks the last of that subset. The Last(FirstN()) pattern gets you the nth record from a table.

    It gets the first record from all split strings and puts them into a row (empty collection+1).
    Then it gets a second record from all split strings and puts them into a row (1+1).
  • Green: Result is the default name of the column that results when you split up strings. You can wrap the entire thing around with Value if you need it to be a number or Text() if you need to format dates and times, etc.

View solution in original post

4 REPLIES 4
JamesM
Level 8

Re: Create a gallery from more than one set of comma delimited string

The closest I've come is splitting each string and using that split as a column in a new collection, 

 

Set(offers,GetMemberSisterClub.Run("2701126726055")); ClearCollect(offerNames,Split(offers.offername,","));ClearCollect(offerExpiries,Split(offers.expiry,",")); Collect(
    OfferList,
    {
        OfferName: Split(offers.offername,","),
        OfferExpiry: Split(offers.expiry,",")
    }
)

 

But it produces columns that have a table inside them, instead of columns of individual values for each row.

 

2019-02-13 16_15_07-LoveMyLoyalty - Saved (Unpublished) - PowerApps.png

Super User
Super User

Re: Create a gallery from more than one set of comma delimited string

Hi @JamesM

This might not be the answer you're looking for, but I think it would be easier if you could modify your Flow so that it returns the results in a 'tabular' layout that you can bind to your Gallery.
 

@Mr-Dang-MSFT wrote a great article on how to output JSON from the 'Respond to PowerApps' function in Flow. I think it's worth trying the same technique.

 

https://powerapps.microsoft.com/en-us/blog/return-an-array-from-flow-to-powerapps-response-method/

 

Also, @ericonline posted a similar question the other week. Perhaps Eric might be able to share how he worked around this issue.

 

https://powerusers.microsoft.com/t5/General-Discussion/Collecting-Part-of-Another-Collection/m-p/211...

 

 

PowerApps Staff Mr-Dang-MSFT
PowerApps Staff

Re: Create a gallery from more than one set of comma delimited string

O I love problems like this!

 

Big idea here is that every nth record lines up among the 3 tables--knowing this is going to help us.

 

There is no way to unite them out of the box. You'll need to bring them together with a repeated action. And when I think of repeated actions, I think of ForAll().

 

Below is the formula I'm suggesting:

 

Clear(joint_collection);

ForAll(any_table,
    Collect(joint_collection,
        {
            column1: Last(FirstN(Split(string1,","),CountRows(joint_collection)+1)).Result,
            column2: Last(FirstN(Split(string2,","),CountRows(joint_collection)+1)).Result,
            column3: Last(FirstN(Split(string3,","),CountRows(joint_collection)+1)).Result...
        }
    )
)

 

 

Let's take this apart.

  • string1, string2, string3 are the strings that are returned from your flow (offers.__)
  • joint_collection is the collection that you want to result by bringing together the respective field from each string
  • any_table could be any one of the split strings since it's just used for determining how many times to loop/repeat the actions, ex: Split(offers.___,",")

 

 

Clear(joint_collection);

ForAll(any_table,
    Collect(joint_collection,
        {
            column1: Last(FirstN(Split(string1,","),CountRows(joint_collection)+1)).Result,
            column2: Last(FirstN(Split(string2,","),CountRows(joint_collection)+1)).Result,
            column3: Last(FirstN(Split(string3,","),CountRows(joint_collection)+1)).Result...
        }
    )
)
  • Red: you already know this part. It's splitting up each string returned from flow.
  • Blue: each time these actions run, one more record is added to the join_collection.

    So this is getting the first n number of records from the split up strings as a table (FirstN). Last() picks the last of that subset. The Last(FirstN()) pattern gets you the nth record from a table.

    It gets the first record from all split strings and puts them into a row (empty collection+1).
    Then it gets a second record from all split strings and puts them into a row (1+1).
  • Green: Result is the default name of the column that results when you split up strings. You can wrap the entire thing around with Value if you need it to be a number or Text() if you need to format dates and times, etc.

View solution in original post

Highlighted
JamesM
Level 8

Re: Create a gallery from more than one set of comma delimited string

Hi everyone, thank you so much for all the great responses, including @Mr-Dang-MSFT and @timl. Your suggestions combined with a couple of other threads here allowed me to settle on the following which has allowed me to iterate through each collection and combine them into a single collection for use in the gallery! This is part of what I love about PowerApps, you're unlikely to find many communities as eager to share and collaborate to bring about success for everyone as creators! <3!

 

Set(
    offers,
    GetMemberSisterClub.Run("2701126726055")
);
ClearCollect(
    offerNames,
    Split(
        offers.offername,
        ","
    )
);
ClearCollect(
    offerExpiries,
    Split(
        offers.expiry,
        ","
    )
);
ClearCollect(
    offerAvailBalances,
    Split(
        offers.availbalance,
        ","
    )
);
ClearCollect(
    offerOpenBalances,
    Split(
        offers.openingbalance,
        ","
    )
);
ClearCollect(
    counter,
    0
);
Clear(Combined);
ForAll(
    offerNames,
    Collect(
        counter,
        Last(counter).Value + 1
    );
    Collect(
        Combined,
        {
            offerAvailBalances: Last(
                FirstN(
                    offerAvailBalances,
                    Last(counter).Value
                )
            ).Result,
            offerOpenBalances: Last(
                FirstN(
                    offerOpenBalances,
                    Last(counter).Value
                )
            ).Result,
            offerNames: Last(
                FirstN(
                    offerNames,
                    Last(counter).Value
                )
            ).Result,
            offerExpiries: Last(
                FirstN(
                    offerExpiries,
                    Last(counter).Value
                )
            ).Result
        }
    )
)

While this is working great, I do look forward to being able to return more complex types from Flow to PowerApps, such as JSON, XML or other easily serializable / de-serializble data formats Smiley Happy  Below is my current UI, the gallery will be the recipient of this data set allowing customers to navigate through their available loyalty offers Smiley Happy  (And yes, the pink is intentional, it's part of the brand Smiley HappyUntitled.png

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

Top Kudoed Authors
Users Online
Currently online: 216 members 3,171 guests
Please welcome our newest community members: