cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
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!
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
)

 

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
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

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

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (74,770)