PowerApps – Filter your drop downs by other fields

Today I tried to create a form in PowerApps where I needed to filter the options available in the drop down depending on an option selected in a different field.

The initial setup

I have the following plumbing already done.

  1. I created a datasource Contact List_1 which is a list of contacts in SharePoint
  2. I created a datasource Opportunities which uses SharePoint  list called Opportunities
  3. The both Opportunities and Contact List have a lookup column called Client
  4. The Contact list has a single line of text column, Fullname
  5. My Opportunity list has multi select lookup column, OpportunityContacts

I now want my PowerApp to only show the contacts relevant to the client selected.

Initially PowerApps would use Choices(Opportunities.OpportunityContacts) to get all my contacts in the Opportunities datasource and my contacts appear in my drop down. This is good but if you want to only show contacts related to a specific client then this isn’t useful. On purpose I called my Client column in my contacts list Company. Just so that it becomes easier to analyse the functions following in this post.

PowerApps filter function

To do the filtering we will need to use the Filter function.

So we would be looking at something like this:

Filter(Choices(Opportunities.OpportunityContacts),<Filter>)

So for each of my contacts I’m going to filter by looking in the Contact List 1 datasource if the Company name matches the client name in my opportunity.

A “Value in <List of contacts>” would be the rough construction that I’m going to use.

Filter(Choices(Opportunities.OpportunityContacts), Value in <List of contacts>)

To filter the list of contacts by the Company name I’m having to look at the data coming from the ‘Contact List 1’ datasource and filter by Company name and rerturn the full name of the contact.

The folloiwng Filter funciton will do this: Filter(‘Contact List_1’, Company = DataCardValueClient.Text).FullName

Putting all the differnt elemtns together I’m looking at this:

Filter(Choices(Opportunities.OpportunityContacts),Value in Filter(‘Contact List_1’, Company = DataCardValueClient.Text).FullName )

 

 

The complete cascaded dropdown

With the above filters in place I’m now getting a drop down that lists only my relevant contacts for a client.

 

Advertisements

7 thoughts on “PowerApps – Filter your drop downs by other fields

  1. I am getting an error “Cannot convert this text value to a record” on the “Value in Filter” in the following. My PlanName is a choice field in the LUPlanContacts list which I created as a Data Source. The “=” sign between Title and PlanNameDataCardValue is giveieng me an error of “Invalid argument type”. I have messed and messed with this and it doesn’t seem to make sense why mine is throwing an error:

    Filter(Choices(LUPlanContacts.PlanName),Value in Filter(‘Plan Directory’,Title=PlanNameDataCardValue.SelectedItems.Value).Authorized_x0020_Signer_x0028_s_)

    Like

    1. I would need to try this out but the problem could be in : PlanNameDataCardValue.SelectedItems.Value

      you are comparing a title with multiple selected items. That doesn’t look right to me.

      Like

      1. HI Misty,

        Can you use both as single selection fields. So that the field you are filtering and the field that is filtered by are both single selection fields only.

        Like

  2. Thank you. I will try moving that field to a multi-choice, as well, to see if it works, but I am still unsure why the error in Value in Filter.

    Like

Please leave a comment or feedback

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.