cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
Community Support
Community Support

Re: Combine Tables to show in a new DataTable

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
Highlighted
Power Apps
Power Apps

Re: Combine Tables to show in a new DataTable

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
        })
)
Highlighted
Anonymous
Not applicable

Re: Combine Tables to show in a new DataTable

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

Highlighted
Anonymous
Not applicable

Re: Combine Tables to show in a new DataTable

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.

Highlighted
Community Support
Community Support

Re: Combine Tables to show in a new DataTable

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.
Highlighted
Anonymous
Not applicable

Re: Combine Tables to show in a new DataTable

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?

Highlighted
Community Support
Community Support

Re: Combine Tables to show in a new DataTable

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

Find your favorite faces from the community presenting at the Power Platform Community Conference!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (6,140)