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 / Set Variable not worki...
Power Apps
Answered

Set Variable not working after doing a clearcollect on visible

(0) ShareShare
ReportReport
Posted on by 113

I am unsure how to explain this. I have 3 filter dropdowns filtering on a gallery. When the app starts I want the dropdowns to default to "ALL". I am populating the dropdowns with collections: 

 

The onvisible for the main screen is:

ClearCollect(
   colProjects,
   AddColumns('Project and Status',"ProjectTypeText",Project_x0020_Type.Value,
   "ProjectMgrText", Project_x0020_Manager.DisplayName));
ClearCollect(
   colProjectType,
   Distinct(colProjects,ProjectTypeText));
   Collect(colProjectType,{Result:"All"});
ClearCollect(
   colProjectMgr,
   Distinct(colProjects,ProjectMgrText));
   Collect(colProjectMgr,{Result:"All"});
ClearCollect(
   colCustomer,
   Distinct(colProjects,Customer_x0020_ID));
   Collect(colCustomer,{Result:"All"});
ClearCollect(
   colFilterProjects,colProjects);
Set(varAll,"All")

 

I have the Onchange of each dropdown:

ClearCollect(
   colFilterProjects,
   Filter(colProjects,
   Customer_x0020_ID = drpCustomer.Selected.Result ||drpCustomer.Selected.Result = "All",
   ProjectMgrText = drpProjectMgr.Selected.Result ||drpProjectMgr.Selected.Result = "All",
   ProjectTypeText = DrpProjectType.Selected.Result ||DrpProjectType.Selected.Result = "All"
))

I also have the "default" = varAll and the "Items" = 

Customer = Sort(colCustomer,Result) 

Project Type = Sort(colProjectType,Result)

Project Lead = Sort(colProjectMgr,Result)

 

When i start the App, the default is never "All" and when i navigate back to the main page after setting them all to "All" it always defaults to the first selection not "All"

 

I have tried using the same script used on the on visible, in the on start. I have tried just putting the Set(varAll,"All") on navigations from other screens to the main. I am not coming up with anymore ideas. Have been trying all sorts of things. 

Any help would be appreciated. 

Categories:
  • Eickhel Profile Picture
    374 Most Valuable Professional on at

    Ok, I've built a test app with this:

     

    OnVisible:

    ClearCollect(types, Choices('Powered List'.Receipt_x0020_type));
    Collect(types, "All")

    I had a ComboBox so:

    Items:

    types

    DefaultSelectedItems:

    Last(types)

    Since the "All" item was the last one on the list, it gets selected from the collection.

     

    I hope this works.

  • KroonOfficeSol Profile Picture
    587 on at

    Hi Rebeccak,

     

    First, next time place your code in a codeblock, this makes it easier to read.

     

    Next, get rid off the DropDownbox and replaces them bij ComboBoxes. Disable the multiselect and optional the search parameter.

     

    Then do this OnVisible:

    ClearCollect(colProjects, AddColumns('Project and Status',"ProjectTypeText",Project_x0020_Type.Value,"ProjectMgrText", Project_x0020_Manager.DisplayName));
    ClearCollect(colProjectType,Distinct(colProjects,ProjectTypeText));
    ClearCollect(colProjectMgr,Distinct(colProjects,ProjectMgrText));
    ClearCollect(colCustomer,Distinct(colProjects,Customer_x0020_ID));
    ClearCollect(colFilterProjects,colProjects);
    Set(varAll,"All")

    Default the Combobox will be empty and you can use the Searchtext to tell please what to do (On this moment when search is enabled, but I post the idea for a hinttext on this control.)

     

    Then on the controls do like this:

    ClearCollect(colFilterProjects,
    Filter(colProjects,
    (IsBlank(drpCustomer.Selected.Result) || Customer_x0020_ID = drpCustomer.Selected.Result),
    (IsBlank(drpProjectMgr.Selected.Result) || ProjectMgrText = drpProjectMgr.Selected.Result)
    // (IsBlank(DrpProjectType.Selected.Result) || ProjectTypeText = DrpProjectType.Selected.Result)
    //Don't put in a line for the combobox itself
    )
    )

    You must remove the line which states the combobox itselfs (so with 3 controls you get 2 lines). The IsBlank() will be true when the combobox is empty, so basically when both comboboxes are empty the first condition in a line will be true. 

     

    Maybe you should add a reset() formula also to reset specific boxes on selection, mostly this you will do from the first combo (for the second and third) and the second combo (for the third). 

     

    Use the same IsBlank() formula for filtering your gallery (if you use one) and it should work.

     

    Hope this helps.

     

    Paul

  • Verified answer
    Rebeccak Profile Picture
    113 on at

    I was able to keep the dropdowns and everything I had on the onvisible. I just added reset(drpcustomer);reset(drpprojecttype);reset(projectMgr)

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 Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 402 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 296 Most Valuable Professional

Last 30 days Overall leaderboard