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

Dynamic dropdowns

Hello,

         I am looking for a little help with populating dynamic dropdowns based on a users choice via a dropdown.

I have a gallery that will display all items from the collection colSars. The user has the option of refining that search using 2 dropdowns and a search bar.

The first dropdown allows them to filter by application and the second dropdown allows them to filter by module. 

The problem i am having is that when a user selects an application from the first dropdown i would like to then only give them the available modules in the second dropdown, currently is just displays all of them. 

Here is the items code i currently have that just filters by each dropdown and search.

SortByColumns(
    Search(
        If(
            ddApp.Selected.Result = "All" && ddMod.Selected.Result = "All",
            colSars,
            ddApp.Selected.Result = "All" && ddMod.Selected.Result <> "All",
            Filter(
                colSars,
                Module.Value = ddMod.Selected.Result
            ),
            ddApp.Selected.Result <> "All" && ddMod.Selected.Result = "All",
            Filter(
                colSars,
                Application.Value = ddApp.Selected.Result
            ),
            ddApp.Selected.Result <> "All" && ddMod.Selected.Result <> "All",
            Filter(
                colSars,
                Application.Value = ddApp.Selected.Result && Module.Value = ddMod.Selected.Result
            )
        ),
        TextInput1.Text,
        "{Name}"
    ),
    "Modified",
    Descending
)

 

I'm not sure if i would need to re-collect the collection colSars or if i am able to add a Distinct tag to each condition to filter down the modules depending on the application that is chosen in the first dropdown. 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

@stephenJames 

Yes, so the fact is that you are basing the second dropdown (Modules) on the collection.  The collection will not change.  You can filter on the collection, but because of the fact that you used Distinct on the list, this means that any criteria (Application) will be missing and you can no longer refine those results.

 

My suggestion...for the Items property of your Modules dropdown, set the formula to the following:

With({results:
    Distinct(
        Filter(colSars,
            ddApp.Selected.Result = "All" || Application.Value = ddApp.Selected.Result
        ),
        Module.Value
    )
    },
    ForAll(
        Sequence(CountRows(results)+1),
        {Result: If(Value-1 = 0, "All", Last(FirstN(results, Value-1)).Result)}
    )
)

This will filter the list if so indicated by the first dropdown (Application).

You can get rid of the colMod collection then as it is no longer needed.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

4 REPLIES 4
Super User III
Super User III

@stephenJames 

First consider changing your formula to the following to simplify it:

SortByColumns(
    Search(
        Filter(
            colSars,
            (ddMod.Selected.Result = "All" || Module.Value = ddMod.Selected.Result) &&
            (ddApp.Selected.Result = "All" || Application.Value = ddApp.Selected.Result)
        ),
        TextInput1.Text,
        "{Name}"
    ),
    "Modified",
    Descending
)

 

Now...the above formula is your Items property presumably from a Gallery. 

What is the items formula on the Second dropdown you have?  That is where you would want to filter to the module.

Something along these lines (a bit of a guess as I do not know what you have there on the data):

Distinct(
    Filter(colSars,
        (ddApp.Selected.Result = "All" || Application.Value = ddApp.Selected.Result)
    ),
    Module.Value
)
    

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

Hi @RandyHayes ,

                             Thanks for your help. The code you provide helped a lot with simplification

SortByColumns(
    Search(
        Filter(
            colSars,
            (ddMod.Selected.Result = "All" || Module.Value = ddMod.Selected.Result) &&
            (ddApp.Selected.Result = "All" || Application.Value = ddApp.Selected.Result)
        ),
        TextInput1.Text,
        "{Name}"
    ),
    "Modified",
    Descending
)

 

So for each drop down the items property is set to colApp for the application dropdown and colMod for the module dropdown. 

These are getting their values from this code on App start

ClearCollect(colApp, {Result: "All"});
Collect(colApp, Distinct(colSars, Application.Value));
ClearCollect(colMod, {Result: "All"});
Collect(colMod, Distinct(colSars, Module.Value));

I did this at App start to have all the values from both application and module as the gallery displays everything from the colSars collection by default. 

 

 

@stephenJames 

Yes, so the fact is that you are basing the second dropdown (Modules) on the collection.  The collection will not change.  You can filter on the collection, but because of the fact that you used Distinct on the list, this means that any criteria (Application) will be missing and you can no longer refine those results.

 

My suggestion...for the Items property of your Modules dropdown, set the formula to the following:

With({results:
    Distinct(
        Filter(colSars,
            ddApp.Selected.Result = "All" || Application.Value = ddApp.Selected.Result
        ),
        Module.Value
    )
    },
    ForAll(
        Sequence(CountRows(results)+1),
        {Result: If(Value-1 = 0, "All", Last(FirstN(results, Value-1)).Result)}
    )
)

This will filter the list if so indicated by the first dropdown (Application).

You can get rid of the colMod collection then as it is no longer needed.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

@RandyHayes ,

                        Thank you very much for your help on this.

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (6,996)