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

Filter by related Salesforce records

I have a Gallery in my app where I want to show Accounts from Salesforce that have specific related Opportunities. I am passing the Opportunity IDs from another screen in my app.

 

When I try to create a Filter formula, the only fields that I can filter by are Account fields. I get an "invalid field" error if I try to look up through a related list. Anyone know how to filter through a Salesforce related list in PowerApps, or a workaround to get my desired result?

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @AtlantisFury ,

Based on the formula that you mentioned, I think there is something wrong with it.

 

The Opportunity__c field would return a unique record id, there is no sub-properties exposed under the Opportunity__c field. If you want to retrieve corresponding Opportunity Name through ThisItem.Opportunity__c.Name formula, I afraid that there is no way to achieve your needs.

 

As an fixed solution, you need to retrieve the corresponding Opportunity Name from your Opportunities Table based on the unique Opportunity__c value.

 

Within your Gallery, you could consider set the Text property of the Label to following:

LookUp(
       'Opportunities Table',
        Opportunity__c = SelectedRoom.Opportunity__c,
        Name
)

or

LookUp(
       'Opportunities Table',
        Opportunity__c = SelectedRoom.Opportunity__c
).Name

Note: The Name represents the field in your Opportunities Table, to store the Opportunity Name.

 

Please take a try with above solution, then check if the issue is solved.

 

Best regards,

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

5 REPLIES 5
v-xida-msft
Community Support
Community Support

Hi @AtlantisFury ,

Could you please share a bit more about the Filter formula you used in your app?

Do you want to filter your Accounts table records from your Saleforce based on specific Opportunity IDs?

 

Based on the needs that you mentioned, I afraid that there is no filtered column within your Accounts table to compare with the passed Opportunity ID value.

 

As an alternative solution, you could consider get all related account names based on the passed Opportunity ID value from your Opportunity Table, then filter your Accounts Records based on the filtered related account names.

 

I have made a test on my side, please consider take a try with the following workaround:

Set the Items property of the Gallery to following:

Filter(
       AccountsTable,
       'Account Name' in Filter(
                                OpportunitiesTable,
                                OpportunityID = "Specific Opportunity ID value passed from another screen"
                         ).'Account Name'
)

Note: The first 'Account Name' represents the Text column in your Accounts Table. The second 'Account Name' field represents the LookUp column in your Opportunity Table.

 

If there is a sub-property under the 'Account Name' LookUp column, please modify above formula as below:

Filter(
       AccountsTable,
       'Account Name' in Filter(
                                OpportunitiesTable,
                                OpportunityID = "Specific Opportunity ID value passed from another screen"
                         ).'Account Name'.Sub-property
)

Note: The 'Account Name' value (from your Accounts Table) is stored within the Sub-property under the 'Account Name' LookUp column (from your Opportunity Table).

 

Best regards,

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.

Hi @v-xida-msft ,

Thank you for your suggestion, but unfortunately, it did not work. Using your suggested syntax, I edited my formula to be the following; it does not return an error, but it also does not return any results in my gallery.

( I had to create a collection for my data source due to a delegation error for the "in" function and the number of records in my "Accounts" Salesforce database)

Filter(AccountsColl,Id in Filter(Opportunities,Id = SelectedRoom.Id).AccountId)

 

In my Salesforce org, I also have a junction object that provides a many to many relationship between Accounts and Opportunities. I decided to try using that object as the data source for my Gallery, using your suggestion of using .Sub-property to access related fields through the lookup field.

 

This Items formula returns records in my gallery, but PowerApps fails to retrieve the field values that I want to display by using the .Sub-property through lookup fields in Salesforce.

 

Here is the Items function that is currently working:

Filter('Guest to Opp Associations',Opportunity__c=SelectedRoom.Opportunity__c)

 

Here is the formula for the value I want to display in my Gallery, but PowerApps fails to resolve:

ThisItem.Opportunity__r.Name

I have also tried:

ThisItem.Opportunity__c.Name

 

-AtlantisFury

Hi @AtlantisFury ,

Based on the formula that you mentioned, I think there is something wrong with it.

 

The Opportunity__c field would return a unique record id, there is no sub-properties exposed under the Opportunity__c field. If you want to retrieve corresponding Opportunity Name through ThisItem.Opportunity__c.Name formula, I afraid that there is no way to achieve your needs.

 

As an fixed solution, you need to retrieve the corresponding Opportunity Name from your Opportunities Table based on the unique Opportunity__c value.

 

Within your Gallery, you could consider set the Text property of the Label to following:

LookUp(
       'Opportunities Table',
        Opportunity__c = SelectedRoom.Opportunity__c,
        Name
)

or

LookUp(
       'Opportunities Table',
        Opportunity__c = SelectedRoom.Opportunity__c
).Name

Note: The Name represents the field in your Opportunities Table, to store the Opportunity Name.

 

Please take a try with above solution, then check if the issue is solved.

 

Best regards,

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

Hello @v-xida-msft ,

 

Thank you for your reply.

 

I have used your suggested workaround to get the information I need in my gallery.

 

One thing I would like to point out though. You stated:

"The Opportunity__c field would return a unique record id, there is no sub-properties exposed under the Opportunity__c field. If you want to retrieve the corresponding Opportunity Name through ThisItem.Opportunity__c.Name formula, I afraid that there is no way to achieve your needs."

 

That is not exactly true. In Salesforce, using Lookupfield__r to replace Lookupfield__c in a formula allows you to pass through a lookup field to get values from a related record. That is native functionality in Salesforce. It would be great if PowerApps could extend the functionality of their connector to take advance of this. While using your workaround will work, it significantly increases the number of API calls that my app uses which has a limit in Salesforce.

 

-AtlantisFury

Hi again @v-xida-msft ,

 

Another question for you,

 

Any idea why the Text formula in the Label of my Gallery only works directly with the data source and not with a collection?

If I use "Accounts" from Salesforce as my data source, the Label populates properly in my Gallery, but if I use my "AccountsColl" collection, I get the error "This Formula uses scope, which is presently not supported for evaluation" and my label does not populate.

Capture.PNG

 

 

 

 

-AtlantisFury

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,244)