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 / Cascading dropdown fil...
Power Apps
Suggested Answer

Cascading dropdown filter

(1) ShareShare
ReportReport
Posted on by 35
Hello,
 
I would like to ask if there are anyone who knows how i should update my current code (See below). I need it to function so that whenever i have selected "All" in my company dropdown, then my department dropdown needs to only return "All" or "None", whereas right now it does return those two however it also returns all other departments which makes for a very long list. The second part of my code where it filters the departments whenever a specific company is selected is working as intended but its the first part that i would like some advice one.
 
Thank you!
 
 
If(
IsBlank(Dropdown3_1.Selected.Company),
Sort(colDeptSplit, Dept, SortOrder.Descending),
If(
Dropdown3_1.Selected.Company = "All",
Filter(
colDeptSplit,
Dept = "All" || Dept = "None"
),
Ungroup(
Table(
{Data: Table({Dept: "None"})},
{
Data: Sort(
Filter(
colDeptSplit,
Company = Dropdown3_1.Selected.Company
),
Dept,
SortOrder.Ascending
)
}
),
Data
)
)
)
I have the same question (0)
  • Suggested answer
    Haque Profile Picture
    3,653 on at
    Hi @NicoPet
     
    Before everyting, I would request when you paste code - please use "Insert Code Snippet" for better readability.
     
    If I understood correctly, when Dropdown3_1.Selected.Company = "All", seems like you’re still filtering against colDeptSplit, which means it’s pulling every department that matches "All" or "None".  Basically,  "All" isn’t a department really  in the dataset, the filter ends up returning everything plus "None".
     
    Let's try this block
    If(
        IsBlank(Dropdown3_1.Selected.Company),
        Sort(colDeptSplit, Dept, SortOrder.Descending),
        If(
            Dropdown3_1.Selected.Company = "All",
            Table(
                {Dept: "All"},
                {Dept: "None"}
            ),
            Ungroup(
                Table(
                    {Data: Table({Dept: "None"})},
                    {
                        Data: Sort(
                            Filter(
                                colDeptSplit,
                                Company = Dropdown3_1.Selected.Company
                            ),
                            Dept,
                            SortOrder.Ascending
                        )
                    }
                ),
                Data
            )
        )
    )
    
    Where Table({Dept: "All"}, {Dept: "None"}) - will return only those two values, no reference to colDeptSplit. This will ensures your Department dropdown shows exactly "All" and "None" when the Company dropdown is "All"
     
    Filter(colDeptSplit, Dept = "All" || Dept = "None") --->  Table({Dept:"All"}, {Dept:"None"}) did the trick.
     
     

    I am sure some clues I tried to give. If these clues help to resolve the issue brought you by here, please don't forget to check the box Does this answer your question? At the same time, I am pretty sure you have liked the response!
     
  • WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    Firstly, @Haque may be correct here and I am reading this incorrectly - I am assuming that "All" and "None" are actual values in your field Dept. I am also allowing for "None" to be added to your final Table only when there is a value selected in Dropdown3_1 (which seems to be the intent of your code). The other thing suggested is a different condensed structure that may be useful.
    With(
       {
          _Data:
          Sort(
             Filter(
                colDeptSplit,
                Len(Dropdown3_1.Selected.Company) = 0 ||
                (
                   Dropdown3_1.Selected.Company = "All" &&
                   (Dept = "All" || Dept = "None")
                ) ||
                Company = Dropdown3_1.Selected.Company
             ),
             Dept,
             SortOrder.Ascending
          )
       },
       If(
          Len(Dropdown3_1.Selected.Company) = 0,
          _Data,
          Table(
             {Dept: "None"},
             _Data
          )
       )
    )
     
    Please ✅ Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like ♥
    Visit my blog
    Practical Power Apps    LinkedIn  
  • NicoPet Profile Picture
    35 on at
    @WarrenBelz
    @Haque

    Neither solutions worked, let me try to clarify. If the selection in Company is "All" then it needs to populate the dropdown for Department with "All" and "None" and filter out any other value. If i have selected a specific company in the dropdown, then it needs to filter only departments that are related and add "None" option (as mentioned this part already works as intended). 
  • WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    Can you please clarify "worked" - I ran my code through a model and got the following: -
    • When nothing selected in the drop-down, all records are displayed. This is my full test dataset with Company on the left, Dept on the right
    • When All selected in the Drop-down, all records where the Dept was All or None were produced as well as an item at the top with None in the Dept field (I also added it in the Company field for testing).

       
    • When another Dept was selected, all records for that Dept as well as the extra item above
     
    What in the above is not to the requirements you posted ?
     
    Please ✅ Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like ♥
    Visit my blog
    Practical Power Apps    LinkedIn  
  • NicoPet Profile Picture
    35 on at
    @WarrenBelz

    Thank you replying, I think the issue lies in that i dont have a department called "All", the "All" option is a constructed value that i only need if the company selection is All. Currently the code i am using does in fact return "All" however it also return every other department because i have not selected a specific company to filter by
  • WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    OK - I am a little unclear now - if you do not have a value in Dept called All, what exactly do you want returned when All is selected ?
  • WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    A quick follow-up to see if you received the answer you were looking for. Happy to assist further if not.
     
    Please ✅ Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like â™¥
    Visit my blog
    Practical Power Apps    LinkedIn   

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