cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Nayfen
New Member

Gallery Item Filter using 2 Combo boxes + Show all Items when boxes empty

Been trying to get this working for ages and could use some assistance:

 

If(

    _varSiteAdmin,

    If(

        IsBlank(drpRequestStatusFilter.SearchText),

        If(

            IsBlank(cmbRequestTypeFilter.Selected.Result),

            Sort(

                CustomerRequests,

                Created,

                Descending

            ),

            Sort(

                Filter(

                    CustomerRequests,

                    'Customer Request Type' exactin cmbRequestTypeFilter.Selected.Result

                ),

                Created,

                Descending

            )

        ),

        If(

            IsBlank(cmbRequestTypeFilter.Selected.Result),

            Sort(

                Filter(

                    CustomerRequests,

                    Status = drpRequestStatusFilter.Selected.Result

                ),

                Created,

                Descending

            ),

            Sort(

                Filter(

                    CustomerRequests,

                    Status = drpRequestStatusFilter.Selected.Result And 'Customer Request Type' exactin cmbRequestTypeFilter.Selected.Result

                ),

                Created,

                Descending

            )

        )

    ),

    /*isAdmin False/Else Value Code:*/

    If(

        IsBlank(drpRequestStatusFilter.SearchText),

        If(

            IsBlank(cmbRequestTypeFilter.Selected.Result),

            Sort(

               Filter(

                    CustomerRequests,

                    'Customer Email' exactin _varUserEmail

                ),

                Created,

                Descending

            ),

            Sort(

                Filter(

                    CustomerRequests,

                    'Customer Request Type' exactin cmbRequestTypeFilter.Selected.Result And 'Customer Email' exactin _varUserEmail

                ),

                Created,

                Descending

            )

        ),

        If(

            IsBlank(cmbRequestTypeFilter.Selected.Result),

            Sort(

                Filter(

                    CustomerRequests,

                    Status = drpRequestStatusFilter.Selected.Result And 'Customer Email' exactin _varUserEmail

                ),

                Created,

                Descending

            ),

            Sort(

                Filter(Filter(

                    CustomerRequests,

                    Status = drpRequestStatusFilter.Selected.Result And 'Customer Request Type' exactin cmbRequestTypeFilter.Selected.Result), 'Customer Email' exactin _varUserEmail

                ),

                Created,

                Descending

            )

        )

    )

)

 

The code has no errors but just doesn't seem to like the current configuration.

 

_varSiteAdmin is set OnStart by the following code:

 

If(Is blank(Lookup ('Lookup - AdminSettings','Setting Type' exactin "Site Admin" And 'Setting Value' exactin _varUserName)), Set(_varSiteAdmin,false),Set(_varSiteAdmin,true))

 

This code is fine and works for my purposes but the Items code above is what is no longer working.

 

I want to be able to use two separate combo boxes to filter results and if the boxes are empty/if you remove a selected option from combo box then I want it to show all items.

 

Thanks in anticipation

4 REPLIES 4
RandyHayes
Super User III
Super User III

@Nayfen 

Please consider changing your Formula to the following:

Sort(
    Filter(CustomerRequests,
    (IsBlank(cmbRequestTypeFilter.Selected.Result) || 'Customer Request Type' in cmbRequestTypeFilter.Selected.Result) &&
    (IsBlank(drpRequestStatusFilter.Selected.Result) || Status = drpRequestStatusFilter.Selected.Result) &&
    (_varSiteAdmin && 'Customer Email' in _varUserEmail),
    Created,
    Descending
)

This should give you what you are looking for.

 

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!
Nayfen
New Member

Hi Randy, thanks for the quick response! So your suggesting to replace everything in the items (my first shared code) with the code you've provided?

 

I tried doing this and it's missing a closing Parentheses. That last ) is closing off the filter not the sort.

 

I added a closing Parentheses at the end and it shouted at me.

 

Sort(
    Filter(CustomerRequests,
    (IsBlank(cmbRequestTypeFilter.Selected.Result) || 'Customer Request Type' in cmbRequestTypeFilter.Selected.Result) &&
    (IsBlank(drpRequestStatusFilter.Selected.Result) || Status = drpRequestStatusFilter.Selected.Result) &&
    (_varSiteAdmin && 'Customer Email' in _varUserEmail),
    Created,
    Descending
)

I added it after _varSiteAdmin) and that seems to have done it (no errors), but not seeing any items displayed in the gallery.

 

Thanks

@Nayfen ,

Firstly, credit @RandyHayes with this solution - you are missing another parenthesis (or have an extra one depending on how you deal with the last bit). If you indent the syntax properly, you will see it

Sort(
   Filter(
      CustomerRequests,
      (
         IsBlank(cmbRequestTypeFilter.Selected.Result) || 
         'Customer Request Type' in cmbRequestTypeFilter.Selected.Result
      ) &&
      (
         IsBlank(drpRequestStatusFilter.Selected.Result) || 
         Status = drpRequestStatusFilter.Selected.Result
      ) &&
      _varSiteAdmin && 'Customer Email' in _varUserEmail
   ),
   Created,
   Descending
)

 

RandyHayes
Super User III
Super User III

@Nayfen 

Thanks for the catch @WarrenBelz ...you know how it goes when typing formulas by hand!  I wish the forum had a formula editor 😉

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

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!

secondImage

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (106,138)