cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
IntraAdmin
Helper II
Helper II

Use All in a dropdown to filter gallery not working

I have a dropdown for filtering my gallery by a choice field but would like to add "All" so that all items will show in gallery if "All" is chosen.  I am using formulas I have used before in a different tenant but can't seem to get the filter to work or even display values.  I don't recall where or how to add "All".  I have created a collection OnStart but that doesn't seem to populate.  I think I have been staring at this for too long. Below is the code and attached are errors received.  Any help is much appreciated.

 

OnStart:

If(
    varView = "New", Office365Users.UserProfileV2(User().FullName),
    EmailDataCardValue.Selected
);
ClearCollect(colCategories, {Value:"All"}, Choices('AIMS Q & A'.Category));Collect(colCategories,Choices('AIMS Q & A'.Category))

ddCategorySearch.Items

With({_items: Sort(Distinct('AIMS Q & A', Category.Value),Result)},
ForAll(Sequence(CountRows(_items)+1,0),
{Result: If(Value=0, "All", Last(First(_items, Value)).Result)}

 Gallery1.Items

SortByColumns(
    Search(
        Filter(
            'AIMS Q & A',
            ddCategorySearch.Selected.Result = "All" || Category.Value = ddCategorySearch.Selected.Result
        ),
        txtRequestor.Text
        
    ),
    "Created"
)

 

4 REPLIES 4
WarrenBelz
Super User
Super User

Hi @IntraAdmin ,

'Firstly your collection only needs the first bit

ClearCollect(
   colCategories, 
   {Value:"All"},
   Choices('AIMS Q & A'.Category)
)

 

Can you please explain in a bit more detail what you are trying to do here.

With(
   {
      _items: 
      Sort(
         Distinct(
            'AIMS Q & A', 
            Category.Value
         ),
         Result
      )
   },
   ForAll(
      Sequence(
         CountRows(
            _items
         )+1,
         0
      ),
      {
         Result: 
         If(
            Value=0, 
            "All", 
            Last(
               First(
                  _items, 
                  Value
               )
            ).Result
         )
      }
   )
)
IntraAdmin
Helper II
Helper II

Hi, @WarrenBelz ,

 

Thank you for your feedback.  In the ddSearchCategory.Items I am trying to get the values to search Gallery1 by the field Category.  What I feel the code is doing is the following:

Take the distinct values in the Category field then ForAll the distinct values create a table to put in ddSearchCategory. If the sequence number is 0 then the value is All else other values.  

 

This works in another tenant with the same type of field.  But, I do not recall how I got the All in the Choice field (where did I insert it?).   My colCategories seems to always be empty.

IntraAdmin
Helper II
Helper II

@WarrenBelz I changed the ddSearchCategory.Items to colCategories which works well.  I just need to get the distinct values.  Thank you for your assistance.  I had been working on it all day and my brain decided not to function anymore. 🙂

 

@IntraAdmin ,

A bit hard to debug that without actually working on the model, but I probably need to mention that conditional formula in the Items of drop-downs / combo boxes have a habit of not always returning the results desired. Have you thought of doing this as a collection and making this the Items?

 

Please click Accept as solution 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 giving it Thumbs Up.

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

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