cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
KimBim
Advocate I
Advocate I

Joining Tables in Power Apps

Hello Guys,

i have a problem joining two tables in PowerApps. I use SharePoint Lists as my datasources.

 

These are my tables:

Order

IDProjectDateCustomer...
1P-001-Test28.07.2020Peter 

 

OrderPosition

IDOrderIDMaterialAmountUnit
11Rubber10pcs
21Pen20pcs
31Pencil10pcs

 

Since I don't want to drag all the columns from the list "Order" into the list "OrderPosition" i've splitted the lists and would like to join both tables again in a Gallery in PowerApps using the ID from Order and OrderID from OrderPosition.

 

 

I'm stuck at the following point:

//At first I'm collection the orders for a specific project based on a filter (Dropdown)
ClearCollect(
          colProjects;
             Filter(Order;Project="P-001-Test")
);;

//After that i want to collect all the Order positions which have the same OrderID as the ID in my colProjects collection WITHOUT USING IN (can't deal with delegation here)

 

ClearCollect(
        colOrderPosition;
           AddColumns(
              Filter('OrderPosition';OrderID = colProjects.ID);
                  "Project";
                   LookUp(
                                Order;
                                ID = 'OrderPosition'[@OrderID]
)
)
);;

The formula above works if i do not the filtering but then unfortunately i get all the rows from my source OrderPosition, eventhough "Project" is blank.

What i want is to get all the orderpositions to my specific project.

 

Unfortunately there will be a lot of data in this list in a short time, so I want to filter the whole thing by Project or ID from the List Order, so that i do not push tons of data in my app...

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
mdevaney
Super User
Super User

@KimBim 

I looked at general example of how to JOIN two tables in Power Apps inside a collection.

https://matthewdevaney.com/powerapps-collections-cookbook/join-all-columns-from-another-collection/


Here's what I came up with for you.  Please let me know what the result is!

 

//Add all columns from another table code
ClearCollect(mySolution,
    Ungroup(
        DropColumns(
            AddColumns(
                OrderPosition,
                "myGroupedColumn",
                Filter(
                    colProjects,
                    ID=OrderPosition[@OrderID]
                )
            ),
            "OrderID"
        ),
        "myGroupedColumn"
    )
);

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

5 REPLIES 5
Pstork1
Dual Super User
Dual Super User

Rather than joining the lists into a single gallery I would recommend creating a parent child relationship between two galleries.

In the parent gallery list all the records from the order list.  Then in the child gallery filter the records from the order position list to show all the records where the OrderID = gallery1.selected.ID.  As you select orders in the parent table the appropriate records for the Order Position table will show in the other gallery.



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

@KimBim 

I looked at general example of how to JOIN two tables in Power Apps inside a collection.

https://matthewdevaney.com/powerapps-collections-cookbook/join-all-columns-from-another-collection/


Here's what I came up with for you.  Please let me know what the result is!

 

//Add all columns from another table code
ClearCollect(mySolution,
    Ungroup(
        DropColumns(
            AddColumns(
                OrderPosition,
                "myGroupedColumn",
                Filter(
                    colProjects,
                    ID=OrderPosition[@OrderID]
                )
            ),
            "OrderID"
        ),
        "myGroupedColumn"
    )
);

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

v-bofeng-msft
Community Support
Community Support

Hi @KimBim :

Firstly,let me explain why the code "Filter('OrderPosition';OrderID = colProjects.ID)" not work.

The point is OrderID and colProjects.ID have different data types. colProjects.ID is a table.

Secondly,please try this code:

 

ClearCollect(
        colOrderPosition;
           AddColumns(
              Filter('OrderPosition';OrderID = First(colProjects).ID);
                  "Project";
                   LookUp(
                                Order;
                                ID = 'OrderPosition'[@OrderID]
)
)
);;

 

Or

 

ClearCollect(
        colOrderPosition;
           AddColumns(
              Filter('OrderPosition';OrderID in colProjects.ID);
                  "Project";
                   LookUp(
                                Order;
                                ID = 'OrderPosition'[@OrderID]
)
)
);;

 

Best Regards,

Bof

 

Hey @mdevaney Thanks for your replay. 

 

Just fell in love with your cookbook. Man, that's awesome.

 

Unfortunately I still get the error message that certain columns are already in the datasource. For example "Created" or "Created by".
If I modify the query so that I only query the columns that are NOT in both data sources, it works.

 

So I think for now I can work with it very well.

 

Thanks a lot! 🙂

Hey @Pstork1,

thanks for your reply. I think i can use your solution also in my app. So it might be a combination between yours an @mdevaney.

 

Thank you guys 🙂

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,196)