cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Combine Tables to show in a new DataTable

Hi,

 

I have several Strings that I split with the Split function. I then get several different tables... How is it possible to combine these into one table as the strings i am spliting have realation to another.

 

Eks

s1 = "11,21,31"

s2 = "12,22,32"

s3 = "13,23,33"

 

Split on "," gives me 3 different tables..But i want ->

 

Col 1 | Col2 | Col3 |

---------------------------

 11     |   21   |    31

 12     | 22     |  32

 13     |  23    | 33

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @Anonymous,

 

Thanks for your feedback, I afraid that there is no way to achieve your needs in PowerApps currently.

 

If you would like this feature to be added in PowerApps, please submit an idea to PowerApps Ideas Forum:

https://powerusers.microsoft.com/t5/PowerApps-Ideas/idb-p/PowerAppsIdeas

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
Power Apps
Power Apps

You'll need to Collect those splitted strings into a new collection, but it can be done, by extracting each item using the First/FirstN/Last functions. In your example, you'd use something along the lines of the expression below:

Clear(coll);
ClearCollect(temp, Split(s1, ","));
Collect(
    coll,
    {
        Col1: First(temp).Result,
        Col2: Last(FirstN(temp, 2)).Result,
        Col3: Last(temp).Result
    });
ClearCollect(temp, Split(s2, ","));
Collect(
    coll,
    {
        Col1: First(temp).Result,
        Col2: Last(FirstN(temp, 2)).Result,
        Col3: Last(temp).Result
    });
ClearCollect(temp, Split(s3, ","));
Collect(
    coll,
    {
        Col1: First(temp).Result,
        Col2: Last(FirstN(temp, 2)).Result,
        Col3: Last(temp).Result
    })

Another alternative is to use a ForAll loop to do it for all the values that you have:

Clear(coll2);
ForAll(
    [s1, s2, s3],
    Collect(
        coll2,
        {
            Col1: First(Split(Value, ",")).Result,
            Col2: Last(FirstN(Split(Value, ","), 2)).Result,
            Col3: Last(Split(Value, ",")).Result
        })
)
Anonymous
Not applicable

What if I would have it like this -- >

 

s1 = "11,21,31"

s2 = "12,22,32"

s3 = "13,23,33"

 

Col 1 | Col2 | Col3 |

---------------------------

 11     |   12   |    13

 21     | 22     |  23

 31     |  32   | 33

Anonymous
Not applicable

And I do not know have many values the splitted string will give me. All I know is that they have the same amount of values.

Hi @Anonymous,

 

I agree with @CarlosFigueira's thought almost. If you want to combine multiple tables into one table as below:

Col 1 | Col2 | Col3 |
---------------------
 11   |  12  |  13
 21   |  22  |  23
 31   |  32  |  33

Please take a try with the following workaround:13.JPG

 

 

Set the OnVisible property of the first screen to following formula:

UpdateContext({s1:"11,21,31"});UpdateContext({s2:"12,22,32"});UpdateContext({s3:"13,23,33"});
Clear(Collection2);
Collect(Collection2,{
Col1:First(Filter(Split(Concatenate(s1,",",s2,",",s3),","),StartsWith(Result,"1"))).Result,
Col2:Last(FirstN(Filter(Split(Concatenate(s1,",",s2,",",s3),","),StartsWith(Result,"1")),2)).Result,
Col3:Last(Filter(Split(Concatenate(s1,",",s2,",",s3),","),StartsWith(Result,"1"))).Result
});
Collect(Collection2,{
Col1:First(Filter(Split(Concatenate(s1,",",s2,",",s3),","),StartsWith(Result,"2"))).Result,
Col2:Last(FirstN(Filter(Split(Concatenate(s1,",",s2,",",s3),","),StartsWith(Result,"2")),2)).Result,
Col3:Last(Filter(Split(Concatenate(s1,",",s2,",",s3),","),StartsWith(Result,"2"))).Result
});
Collect(Collection2,{
Col1:First(Filter(Split(Concatenate(s1,",",s2,",",s3),","),StartsWith(Result,"3"))).Result,
Col2:Last(FirstN(Filter(Split(Concatenate(s1,",",s2,",",s3),","),StartsWith(Result,"3")),2)).Result,
Col3:Last(Filter(Split(Concatenate(s1,",",s2,",",s3),","),StartsWith(Result,"3"))).Result
})

Set the Items property of the Data table control to following:

Collection2

 

 

On your side, you should reference to the following formula:

Clear(Collection2);
Collect(Collection2,{
        Col1:First(Filter(Split(Concatenate(s1,",",s2,",",s3),","),StartsWith(Result,"1"))).Result,
        Col2:Last(FirstN(Filter(Split(Concatenate(s1,",",s2,",",s3),","),StartsWith(Result,"1")),2)).Result,
        Col3:Last(Filter(Split(Concatenate(s1,",",s2,",",s3),","),StartsWith(Result,"1"))).Result
});
Collect(Collection2,{
        Col1:First(Filter(Split(Concatenate(s1,",",s2,",",s3),","),StartsWith(Result,"2"))).Result,
        Col2:Last(FirstN(Filter(Split(Concatenate(s1,",",s2,",",s3),","),StartsWith(Result,"2")),2)).Result,
        Col3:Last(Filter(Split(Concatenate(s1,",",s2,",",s3),","),StartsWith(Result,"2"))).Result
});
Collect(Collection2,{
        Col1:First(Filter(Split(Concatenate(s1,",",s2,",",s3),","),StartsWith(Result,"3"))).Result,
        Col2:Last(FirstN(Filter(Split(Concatenate(s1,",",s2,",",s3),","),StartsWith(Result,"3")),2)).Result,
        Col3:Last(Filter(Split(Concatenate(s1,",",s2,",",s3),","),StartsWith(Result,"3"))).Result
})

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

But this don't work when the number of elements varies.. I would like a general method for iterating over the splitted elements. 

 

In any other language i would just wrote a for-loop where i indexed on the splitted string

For example something like this

for i = 0 ; i<= s1.split(",").lenght() ; i++ :

     e1 = s1.split(",")[i]

     e2 = s2.split(",")[i]

     e3 = s3.split(",")[i]

     ...do something

 

Are there not any methods of doing a normal for-loop in PowerApps?

Hi @Anonymous,

 

Thanks for your feedback, I afraid that there is no way to achieve your needs in PowerApps currently.

 

If you would like this feature to be added in PowerApps, please submit an idea to PowerApps Ideas Forum:

https://powerusers.microsoft.com/t5/PowerApps-Ideas/idb-p/PowerAppsIdeas

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (8,992)