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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Filter Records In A Ga...
Power Apps
Suggested Answer

Filter Records In A Gallery Based On Multiple Related Records

(2) ShareShare
ReportReport
Posted on by 4
Hi everyone! I have the following database structure.
 
1 Opportunity : N "Opportunity Accounts" (to link multiple children Accounts from the "Customer" to an Opportunity). For example, BIG ACCOUNT has 10 total children Accounts. A new Opportunity is created for BIG ACCOUNT where only three of its 10 children are related to the Opportunity.
  • Child Account A
  • Child Account B
  • Child Account C
Each of those children Accounts will have an Opportunity Account record for them tied to the Opportunity.
 
I then want to then show all Contacts that are associated with either Child Account A, Child Account B, or Child Account C in a gallery embedded on an Opportunity form.
 
 
Is this possible? I haven't had any luck with creating a formula for it.
 
 
Categories:
I have the same question (1)
  • Suggested answer
    VASANTH KUMAR BALMADI Profile Picture
    322 on at

    This is a classic N:N relationship filtering scenario in Dataverse, and you’re very close — you just need the correct relationship chain.

    Your data model looks like this:

    Opportunity
       ↓
    Opportunity Account (intersect table)
       ↓
    Account (child)
       ↓
    Contact
    

    What you want is:

    Show all contacts belonging to the child accounts that are linked to the current opportunity.

    ✅ Recommended approach (works in model-driven apps)

    You should not try to do this with FetchXML manually in the form or with JavaScript.

    Dataverse already supports this using related tables + filtering.

    ✅ Step-by-step solution

    1️⃣ Relationships required

    You must have:

    • Opportunity → Opportunity Account
      (1:N)

    • Opportunity Account → Account
      (N:1)

    • Account → Contact
      (1:N, standard relationship)

    No custom logic required.

    2️⃣ Create a Contact subgrid on Opportunity

    On the Opportunity main form:

    • Insert Subgrid

    • Table: Contacts

    • View: any active contacts view

    Now click Edit related records filtering.

    3️⃣ Configure the relationship path

    Choose:

    Show only related records
    

    Then select this chain:

    Contact
      → Parent Customer (Account)
          → Opportunity Accounts
              → Opportunity
    

    And set:

    Opportunity = Current Opportunity
    

    This tells Dataverse:

    “Show contacts whose parent account is linked to this opportunity through the Opportunity Account table.”

    4️⃣ Result

    If your Opportunity has:

    • Child Account A

    • Child Account B

    • Child Account C

    The subgrid will automatically show:

    • All contacts from Account A

    • All contacts from Account B

    • All contacts from Account C

    No duplicates, no code, no flows.

    ✅ Why this works

    Model-driven apps use relationship traversal, not joins you write manually.

    Behind the scenes Dataverse generates FetchXML similar to:

    Contact
     → Account
         → OpportunityAccount
             → Opportunity
    

    You just define the relationship path once in the subgrid.

    ❌ What you should NOT do

    • ❌ JavaScript filtering

    • ❌ Custom FetchXML web resources

    • ❌ Power Automate to copy contacts

    • ❌ Duplicate contact records

    • ❌ Rollup fields

    All unnecessary.

    ⚠️ Important notes

    ✔ Contacts must use Account as Parent Customer

    (Contacts linked only to Contacts or Leads will not appear.)

    ✔ Opportunity Account must be a proper intersect entity

    (Not a lookup field stored on Opportunity.)

    ✔ Works with security trimming automatically.

    ✅ Final outcome

    When users open the Opportunity:

    • They select child accounts via Opportunity Accounts

    • The embedded Contacts grid dynamically updates

    • Any contact added to those accounts automatically appears

    • No sync, no code, no maintenance

    ✅ This is the same pattern Microsoft uses for:

    • Opportunity Products

    • Quotes → Quote Lines

    • Account Teams

    • Access Teams

    You’re modeling it correctly — you just needed the related-record filter path in the subgrid.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 424

#2
WarrenBelz Profile Picture

WarrenBelz 355 Most Valuable Professional

#3
11manish Profile Picture

11manish 290

Last 30 days Overall leaderboard