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

Creating collection from multiple tables

Hello, is it possible to create a collection based on different tables that are not related?

For example:

 

Table1 -> Names: "Person1", "Person2", "Person3"

Table2 -> Ages: "Age1", "Age2", "Age3"

 

And I want my collection to have a column for Table1 (Names) and a column for Table2 (Ages)

 

Names    |  Ages

_________________

Person1  |  Age1

Person2  |  Age2

Person2  |  Age3

 

The tables are not related, I just want to join them based on their position (the first name with the first age, second name with second age...)

Any ideas?

I can't seem to figure it out

 

1 ACCEPTED SOLUTION

Accepted Solutions
mdevaney
Super User
Super User

@Anonymous 

PowerApps does not have the ability to join tables on based on the position.  I believe the technical term for your concept is a "Cartesian Join" and the resulting table is called a "Cartesian Product".  That's what I remember from learning SQL.

 

The only way to make your join is to edit the data and assign row numbers like so.

 

ClearCollect(
NamesTable,
{row: 1, name: "Person1"},
{row: 2, name: "Person2",
{row: 3, name: "Person3"}
);
ClearCollect(
AgesTable,
{row: 1, age: "Age1"},
{row: 2, age: "Age2",
{row: 3, age: "Age3"}
);

 

Then you would join the columns in another Collection like this

 

ClearCollect(
myJoinedTables,
ShowColumns(
AddColumns(NamesTable,"Age",LookUp(AgesTable,ID=NamesTable[@ID])),
"Name","Age"
)

 

---
Please click "Accept as Solution" if my response helped to solve your issue so that others may find it more quickly. If your thought the post was helpful please give it a "Thumbs Up."

View solution in original post

3 REPLIES 3
Pstork1
Dual Super User
Dual Super User

Not really possible without some kind of Field in common to relate one to the next.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
RezaDorrani
Dual Super User II
Dual Super User II

@Anonymous 

 

Possible but with lots of work to link the 2 collections

 

Firstly you will need to ensure you have an index column on both the lists

Check below post on how to create index (look at the last response from MSFT)

https://powerusers.microsoft.com/t5/Building-PowerApps-Formerly/Patching-an-item-index-number-into-a-collection/td-p/339716

 

Next what you would need to do is the following:

 

ForAll(CollectionTable, Collect(CollectionJoin,{Tables:CollectionTable[@Tables],Ages: Lookup(CollectionAges, Index = CollectionTable[@Index].Ages}))

 

where CollectionTable is name of you table colection with Index column

CollectionJoin is name of new collection

CollectionAges is name of collection with Ages and Index column

 

--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

 

 

mdevaney
Super User
Super User

@Anonymous 

PowerApps does not have the ability to join tables on based on the position.  I believe the technical term for your concept is a "Cartesian Join" and the resulting table is called a "Cartesian Product".  That's what I remember from learning SQL.

 

The only way to make your join is to edit the data and assign row numbers like so.

 

ClearCollect(
NamesTable,
{row: 1, name: "Person1"},
{row: 2, name: "Person2",
{row: 3, name: "Person3"}
);
ClearCollect(
AgesTable,
{row: 1, age: "Age1"},
{row: 2, age: "Age2",
{row: 3, age: "Age3"}
);

 

Then you would join the columns in another Collection like this

 

ClearCollect(
myJoinedTables,
ShowColumns(
AddColumns(NamesTable,"Age",LookUp(AgesTable,ID=NamesTable[@ID])),
"Name","Age"
)

 

---
Please click "Accept as Solution" if my response helped to solve your issue so that others may find it more quickly. If your thought the post was helpful please give it a "Thumbs Up."

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (2,154)