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

Filter syntax issue

I have a filter which starts:

Sort(Filter(
          colCA, If (vCompanyUser <>("Smiths"), CompanyUser, false),
If( ---------a ton of code that basically sets out what should be displayed when a toggle is off or on)

 

What I am trying to achieve is, if our company, “Smiths”, are using the App, we see all the rows in the collection, if any other Company logs in, they only see the rows applicable to that company.   I am pretty sure the <> is wrong but then  !  is only for boolean values.  Maybe my syntax is just plain wrong. 

 

 

11 REPLIES 11
Automate2create
Helper II
Helper II

I've had to extend the code, any help would be appreciated so the logic is as follows:

 

If the company user variable is Smiths, and the ContainerSearch is blank, then return the whole collection but if it is not blank, then return the containersearch records from the collection  

and if the dateactivity is blank, don’t filter on a date, but if it isn’t blank, filter on the date 

if the company user variable is not Smiths and the ContainerSearch is blank, then filter the container records from the collection filtered on the company user but if it is not blank, then return the container records from the collection filtered on the company user 

and if the datactivity is blank, don’t filter on a date but if it isn’t blank, filter on the date  

Whichever method, sort on InputDateTime Descending 

 

This is my code so far, I know it is incorrect but I can't work out how to complete it

 

Sort(
Filter(
colCA,

If(vCompanyUser = "Smiths",

//True
If(IsBlank(cboContainer_2.SelectedItems),
true,
Container.'Container Number' in cboContainer_2.SelectedItems.'Container Number')

&&

If(IsBlank(dteActivity_2.SelectedDate),
true,
dteActivity_2.SelectedDate in Text('Activity Date Time', DateTimeFormat.ShortDateTime)),

OR

//False

vCompanyUser <> "Smiths",
If(IsBlank(cboContainer_2.SelectedItems),
true,
Container.'Container Number' in cboContainer_2.SelectedItems.'Container Number')

&&

If(IsBlank(dteActivity_2.SelectedDate),
true,
dteActivity_2.SelectedDate in Text('Activity Date Time', DateTimeFormat.ShortDateTime)),

)

)
) 'Input Date Time',Descending //sort

 

PowerRanger
Super User
Super User

@Automate2create In order to have the Filter work on a Textfields value or show all if it is empty you have to use this pattern

 

Filter(myDataSource,Title = txtMySearchField.Text || IsBlank(txtMySearchField.Text)

 

And if I have to use different Filters based on a "UserRole" I usually do it in this pattern

 

If(vCompanyUser = "Smiths",
//true
 Filter(myDataSource,Title = txtMySearchField.Text || IsBlank(txtMySearchField.Text),

//False
Filter(myDataSource,Title = txtMySearchField.Text || IsBlank(txtMySearchField.Text, Company = vCompanyUser)

)

 

So basically I really separate the case. I have 1 Sort/Filter formular for one case and another Sort/Filter for the other case.

 

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. 




​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
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,936)