cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
GraemeNZ
Advocate III
Advocate III

Syntax for SortbyColumns/Search/Filter

Hi - I have an app that is now getting a lot of data in the main screen, and I want to add a combo box so the user can filter by a certain customer. On a different screen in the app I have this same setup, except is also includes a textbox where the user can also filter on a name. We also have different levels of security based on whether the user is an approver or not. This is controlled by a global variable like so:

GraemeNZ_0-1653611833652.png

or for a customer:

GraemeNZ_1-1653611866262.png

 

I'm getting lost in the syntax for what I think is an easy change...

 

For the gallery that works, I have this:

//If current user is approver show all, else filter the data based on the customer logged in
SortByColumns(
  Search(
    Filter(
      'Master Ingredients List',
      If(
        gvCurrentUser = "FIW Approver",
        If(IsBlank(cbCustFilter_Ing.Selected.Value),
          true,
          Customer.Value = cbCustFilter_Ing.Selected.Value
        ),
        Customer.Value = gvCustomer
      )
    ),
    TxtIngFilter.Text,
    "Title"
  ),
  "Title",
  Ascending
)

 

I have created a new combo box named cbCustFilter_IngEntry, and I want to remove the TxtIngFilter.Text bit, so I tried this but the syntax is wrong and I can't see how...

 

//If current user is approver show all, else filter the data based on the customer logged in
SortByColumns(
  Search(
    Filter(
      'Master Ingredients List',
      If(
        gvCurrentUser = "FIW Approver",
        If(IsBlank(cbCustFilter_Ing.Selected.Value),
          true,
          Customer.Value = cbCustFilter_IngEntry.Selected.Value
        ),
        Customer.Value = gvCustomer
      )
      ),
    "Title",
    Ascending
)

 

Cheers, GraemeNZ

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenBelz
Super User
Super User

Hi @GraemeNZ ,

You still have Search in the top of the second one, but nothing to search. You can also trim the code down and get rid of Delegation issues

SortByColumns(
   Filter(
      'Master Ingredients List',
      (
         gvCurrentUser = "FIW Approver" &&
         Customer.Value = gvCustomer
      ) ||
      (
         IsBlank(cbCustFilter_Ing.Selected.Value) ||
         Customer.Value = cbCustFilter_IngEntry.Selected.Value
      )
   ),
   "Title",
   Ascending
)

 

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.

Visit my blog Practical Power Apps

View solution in original post

2 REPLIES 2
WarrenBelz
Super User
Super User

Hi @GraemeNZ ,

You still have Search in the top of the second one, but nothing to search. You can also trim the code down and get rid of Delegation issues

SortByColumns(
   Filter(
      'Master Ingredients List',
      (
         gvCurrentUser = "FIW Approver" &&
         Customer.Value = gvCustomer
      ) ||
      (
         IsBlank(cbCustFilter_Ing.Selected.Value) ||
         Customer.Value = cbCustFilter_IngEntry.Selected.Value
      )
   ),
   "Title",
   Ascending
)

 

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.

Visit my blog Practical Power Apps

Thanks @WarrenBelz , I completely forgot to remove the Search. Doh.

 

I'm not sure that your suggested formula does what the old one does. The old code checks if the current user is an approver, and if so they can see all items, or if they select a customer from the combo they will only see that customer's items. If the user is not an approver, then they can only see their own items.

 

Your suggested code looks like it says if the user is an approver, then only display the items where the customer value is blank. If you look at my screenshots in my first post, if gvCurrentUser is FIW Approver, then gvCustomer is blank. Then I get lost as to what the second part does...

 

But nevermind, you helped me with my syntax and it works 🙂 , and I'm not expecting to have a large data set, as there are likely to be less than 500 items in here.

 

Cheers, GraemeNZ

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 (1,214)