cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dlprentice
Responsive Resident
Responsive Resident

How can I add an "All" option to a dropdown?

I've got a data table, and a few dropdowns that let me filter this data table. I'll like to be able to have an "All" option on each of the 3 dropdowns in question to let the end user broaden their search. Is this possible given the code snippets below?

 

Side note: If StateDropdown is set to "All" CityDropdown would need to be forced to set to "All". Once you view the code snippets you will see CityDropdown is dependent on the state selected in the StateDropdown.

 

Data Table (Items):

Filter (
    AddColumns(
        'ESN Ticket Tracker',
        "City",
        LookUp(
            'Networking Device List Master',
            'DNS Entity Name' = 'ESN Ticket Tracker'[@'Service ID'],
            City
        ),
        "State",
        LookUp(
            'Networking Device List Master',
            'DNS Entity Name' = 'ESN Ticket Tracker'[@'Service ID'],
            State
        )
    ),
    Status = StatusDropdown.SelectedText.Value,
    State = StateDropdown.SelectedText.Value,
    City = CityDropdown.SelectedText.Value
)

StatusDropdown (Items)

Sort(Distinct('ESN Ticket Tracker',Status),Result)

StateDropdown (Items)

Sort(Distinct('Networking Device List Master', State),Result)

CityDropdown (Items)

Sort(Distinct(Filter('Networking Device List Master', State=StateDropdown.SelectedText.Value),City),Result)

Screenshot 2021-02-04 072010.png

Screenshot 2021-02-04 072452.png

1 ACCEPTED SOLUTION

Accepted Solutions
JR-BejeweledOne
Super User
Super User

Nesting If statements doesn't always work the way we think it would in Power Apps.    It evaluates each statement until it meets a true condition.   So one of the state conditions is going to be true and it won't even evaluate the If for the city.

 

You have them as separate statements here:

 

State = StateDropdown.SelectedText.Value,
    City = CityDropdown.SelectedText.Value

 

Just add to those like this:

 

If(
AllStates.Value = false,
State = StateDropdown.SelectedText.Value,
State = State,

),

If(
AllCities.Value = false,
City = CityDropdown.SelectedText.Value,
City = City
)

 

)



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

View solution in original post

11 REPLIES 11
JR-BejeweledOne
Super User
Super User

Unless 'All' is an option in the data sources that populate your dropdowns, you will have to do it a different way.

 

I just did something similar last week in an app I am working on.    What I did was to add a checkbox under my dropdown with the option to select 'All'.

 

In your case you could have 2 checkboxes.   Set the default property of the 2nd checkbox to be selected if the 1st one is selected and then modify your filtering to include if those 2 boxes are selected.



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

I understand the idea, would you mind giving a coded example?

I think I'm getting closer,

 

I made a Check box called AllStates and set its default value to this:

true

I made a Check box called AllCities and set its default to this:

If(AllStates.Value=true, true)

 Since I don't have "All" as an option I suppose I'd need to use an If() statement somehow and integrate it into the main "Items" I have:

Filter (
    AddColumns(
        'ESN Ticket Tracker',
        "City",
        LookUp(
            'Networking Device List Master',
            'DNS Entity Name' = 'ESN Ticket Tracker'[@'Service ID'],
            City
        ),
        "State",
        LookUp(
            'Networking Device List Master',
            'DNS Entity Name' = 'ESN Ticket Tracker'[@'Service ID'],
            State
        )
    ),
    Status = StatusDropdown.SelectedText.Value,
    State = StateDropdown.SelectedText.Value,
    City = CityDropdown.SelectedText.Value
)

I'm currently trying to research how to properly nest this in, but if you see something obvious please let me know!

That is exactly what you need to do.    In your If statement, you need to add a filter statement to match your 'All' conditions:   Since you are forcing the Cities to "all' based on the first checkbox, you may be able to get away with just using that one for comparison.    Here is a very basic guide.

 

If(
    citycheckbox = "All",  some filter value,
    Original filter value

)

 

 



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

I think I might have this nested wrong, could you see if you spot anything? It seems to be working but in the wrong order.

 

I seem to only be able to select a specific city and a specific state when AllStates is checked, and AllCities is unchecked. I would only expect this to happen only if both were false.

 

 

 

Filter (
    AddColumns(
        'ESN Ticket Tracker',
        "City",
        LookUp(
            'Networking Device List Master',
            'DNS Entity Name' = 'ESN Ticket Tracker'[@'Service ID'],
            City
        ),
        "State",
        LookUp(
            'Networking Device List Master',
            'DNS Entity Name' = 'ESN Ticket Tracker'[@'Service ID'],
            State
        )
    ),
    Status = StatusDropdown.SelectedText.Value,
    If(
        AllStates.Value = false,
        State = StateDropdown.SelectedText.Value,
        State = State,
        If(
            AllCities.Value = false,
            City = CityDropdown.SelectedText.Value,
            City = City
        )
    )
)

 

 

 StateDropdown (Items):

 

 

Sort(Distinct('Networking Device List Master',State),Result)

 

 

AllStates (Default) Checkbox:

 

 

true

 

 

CityDropdown (Items):

 

 

Sort(Distinct(Filter('Networking Device List Master', State=StateDropdown.SelectedText.Value),City),Result)

 

 

AllCities (Default) Checkbox:

 

 

If(AllStates.Value=true, true)

 

 

 

Screenshot for clarity.

Screenshot 2021-02-04 132150.png

@eka24 Hey! Would you mind helping me out with this one too? 🙂

JR-BejeweledOne
Super User
Super User

Your If statement only evaluates the city if the State is False. is this what you intended?



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

It is not, 

 

I was going for:

 

If box is checked, use the value in the dropdown, otherwise use the default values (I think State = State does that for me).

 

Same with city, figured nesting if() statement would work.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,188)