web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to join 2 tables ?
Power Apps
Unanswered

How to join 2 tables ?

(0) ShareShare
ReportReport
Posted on by 52

Hi,

 

I use the Common Data Service, and I joined some tables without problems.

 

But now, how to join tables in my application and show the label of the second table ?

 

If I have a table Customer join to a Type_Customer table per exemple, how to show in my application the Type_Customer label of a particular Customer ?

 

 Thank you very much!

Categories:
I have the same question (0)
  • Meneghino Profile Picture
    6,949 on at

    Hi @axellefevre

     

    You use the LookUp function to achieve what you need to do, somthing like this:

    LookUp(Type_Customer, PrimaryId = ThisItem.CustomerType.PrimaryId, LabelField)

    Please let me know if this works

     

    PS If performance is slow or becomes slow as you add more data to your database, you should consider caching the Type_Customer table when the App is launched.  Please let me know if this is an issue for you.

     

    PPS Technically you are not really joining two tables (which you can do in PowerApps with the "in" operator) but looking up a value

  • Community Power Platform Member Profile Picture
    on at

    @Meneghino wrote:

    Hi @axellefevre

     

    You use the LookUp function to achieve what you need to do, somthing like this:

    LookUp(Type_Customer, PrimaryId = ThisItem.CustomerType.PrimaryId, LabelField)

    Please let me know if this works

     

    PS If performance is slow or becomes slow as you add more data to your database, you should consider caching the Type_Customer table when the App is launched.  Please let me know if this is an issue for you.

     

    PPS Technically you are not really joining two tables (which you can do in PowerApps with the "in" operator) but looking up a value


    Hi Meneghino,

     

    What about joining 3 tables? I've currently 4 tables: message, customer, customer_contact, contact. customer_contact is a many-to-many relationship between customer and contact. What I really want is fetch the contact names in a dropdownlist on the message screen, but I can only get the contactids. I use this formula to get the contacts: Filter('[dbo].[CUSTOMER_CONTACT]', CustomerID = DropDownListCustomer.Selected.CustomerID)

     Untitled.png

     

     

     

    Best regards,

    Kevin

     

     

  • Meneghino Profile Picture
    6,949 on at

    Hi @Anonymous

    There is a simple approach, let's try that first and see if it works and what performance is like.  Then I suggest you try caching, see the performance improvement, and then choose which approach you prefer.

     

    Simple approach:

     

    Filter('[dbo].[CONTACT]', ID in Filter('[dbo].[CUSTOMER_CONTACT]', CustomerID = DropDownListCustomer.Selected.CustomerID).ContactID)

    Basically the in operator works by selecting all contacts where the ID is included in the list of ContactID returned by your original filter.

    This approach may not work due to both delegation (if your tables have >500 rows) and performance issues.

     

    Caching approach:

     

    Create a welcome screen with a button to navigate to the rest of the app.  The button, before navigation, should cache the contact and customer_contact tables as local collections.  Then you can substitute these in the formula above.  You should be able to find techniques for caching >500 rows in other posts including mine.

     

    Please let me know how you get on.

  • Community Power Platform Member Profile Picture
    on at

    Hi @Meneghino,

     

    Thanks for your advice, but I think it's too complicated. I've come up with another solution. I've changed the dropdownlist to a textbox. When I click on the textbox, I navigate to a new screen with all the contacts filtered by customerid. When I select a contact, I return to the message screen with the contact name filled in. It's more work, but I don't have to mess around with caching tables.

     

    Regards,

    Kevin

  • Community Power Platform Member Profile Picture
    on at

    @Meneghino wrote:

    Hi @Anonymous

    There is a simple approach, let's try that first and see if it works and what performance is like.  Then I suggest you try caching, see the performance improvement, and then choose which approach you prefer.

     

    Simple approach:

     

    Filter('[dbo].[CONTACT]', ID in Filter('[dbo].[CUSTOMER_CONTACT]', CustomerID = DropDownListCustomer.Selected.CustomerID).ContactID)

    Basically the in operator works by selecting all contacts where the ID is included in the list of ContactID returned by your original filter.

    This approach may not work due to both delegation (if your tables have >500 rows) and performance issues.

     

    Caching approach:

     

    Create a welcome screen with a button to navigate to the rest of the app.  The button, before navigation, should cache the contact and customer_contact tables as local collections.  Then you can substitute these in the formula above.  You should be able to find techniques for caching >500 rows in other posts including mine.

     

    Please let me know how you get on.


    Hi Meneghino,

     

    Apparently I still need your method to accomplish my goal. I use the function SaveData to cache the tables locally, but when I execute the LoadData function, I get this error:

     

    description: {"exception":{"stack":"RangeError: Maximum call stack size exceeded\n    at i (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:4590)\n    at m (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:4934)\n    at r (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:6315)\n    at Object.v [as _setErrorValue] (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:6696)\n    at c.Class.derive._creator._setExceptionValue (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:10701)\n    at Object.p [as _notify] (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:5460)\n    at Object.enter (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:9019)\n    at c.Class.derive._oncancel._run (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:10847)\n    at c.Class.derive._oncancel._completed (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:10288)\n    at PromiseQueue._shiftJobsAndStartNextJobIfExists (https://paaweucdn.azureedge.net/v2.0.610.0/studio/js/Core.js?v=39de24830fe0:3848:146)","message":"Maximum call stack size exceeded"},"error":null,"promise":{"_creator":null,"_nextState":null,"_state":{"name":"error","enter":"[function]","cancel":"[function]","done":null,"then":null,"_completed":"[function]","_error":"[function]","_notify":"[function]","_progress":"[function]","_setCompleteValue":"[function]","_setErrorValue":"[function]"},"_value":{},"_isException":true,"_errorId":15,"done":"[function]","then":"[function]"},"id":15,"setPromise":"[function]"}
    stack: RangeError: Maximum call stack size exceeded
        at i (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:4590)
        at m (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:4934)
        at r (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:6315)
        at Object.v [as _setErrorValue] (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:6696)
        at c.Class.derive._creator._setExceptionValue (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:10701)
        at Object.p [as _notify] (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:5460)
        at Object.enter (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:9019)
        at c.Class.derive._oncancel._run (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:10847)
        at c.Class.derive._oncancel._completed (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:10288)
        at PromiseQueue._shiftJobsAndStartNextJobIfExists (https://paaweucdn.azureedge.net/v2.0.610.0/studio/js/Core.js?v=39de24830fe0:3848:146)
    errorNumber: 0
    errorMessage: Maximum call stack size exceeded
    callStack: RangeError: Maximum call stack size exceeded
        at i (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:4590)
        at m (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:4934)
        at r (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:6315)
        at Object.v [as _setErrorValue] (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:6696)
        at c.Class.derive._creator._setExceptionValue (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:10701)
        at Object.p [as _notify] (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:5460)
        at Object.enter (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:9019)
        at c.Class.derive._oncancel._run (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:10847)
        at c.Class.derive._oncancel._completed (https://paaweucdn.azureedge.net/v2.0.610.0/studio/openSource/modified/winjs/js/base.js?v=39de24830fe0:3:10288)
        at PromiseQueue._shiftJobsAndStartNextJobIfExists (https://paaweucdn.azureedge.net/v2.0.610.0/studio/js/Core.js?v=39de24830fe0:3848:146)

     

    Then PowerApps just crashes. I think PowerApps is still limited with the 500 records restriction. Any idea how I can overcome this problem or is there a method to join 2 tables other than [Filter ID in Collection]?

     

    Best regards,

    Kevin

     

  • Meneghino Profile Picture
    6,949 on at

    Hi @Anonymous

    I think it is best to cache in memory, that is with a collection, using ClearCollect if <= records to cache or ClearCollect followed by Collect for >500 records (technique in other posts).

    I have never used SaveData for caching.

  • Community Power Platform Member Profile Picture
    on at

    @Meneghino wrote:

    Hi @Anonymous

    I think it is best to cache in memory, that is with a collection, using ClearCollect if <= records to cache or ClearCollect followed by Collect for >500 records (technique in other posts).

    I have never used SaveData for caching.


    Hi @Meneghino,

     

    I am not able to cache the table in memory, so I've added a dropdownlist to show all the contacts from a selected customer. Here's the formula:

     

    AddColumns(Filter('[dbo].[CUSTOMER_CONTACT]', CustomerID = ThisItem.CustomerID), "FullName", LookUp('[dbo].[CONTACT]', ContactID = CustomerContactID).FullName)

     

    Best regards,

    Kevin

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard