web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Integrating Search wit...
Power Apps
Answered

Integrating Search with a Filter that contains an If statement

(0) ShareShare
ReportReport
Posted on by 18

Hello everyone, I would be most grateful for any advice please on the following:

I have a gallery that is filtered based on a person's role with my company (varRole) whereby the role "QSFI" will only allow that user to view their own form data, whereas other users (managers for example) can see everyone's form data, or an individual's form data based on a dropdown text value.  This works perfectly and the code in the items property of the gallery is:

 

If(
varRole="QSFI",
Filter('TTF Staff Trg',Pilot.Email=varUser.Email),
Filter(
'TTF Staff Trg',
QSFI.Value = DropdownPilot.Selected.Value || If(
DropdownPilot.Selected.Value = " All ",
true,
false
)
)
)

 

I would now like to add a search to this by a single column "ID" and have been trying all sorts of variations without any luck whatsoever.  Most grateful for any thoughts please?

Thanks very much indeed...

Categories:
  • WarrenBelz Profile Picture
    156,550 Most Valuable Professional on at

    Hi @Nelwa ,

    Is ID a text or numeric column ? Also can you please include the code you have attempted

  • Nelwa Profile Picture
    18 on at

    Hi Warren and thanks for the reply.  ID is a number.  I started trying to sort the filtered gallery by ID using both Sort and SortByColumns, but could not get this working.  I then thought I would try a search instead (which is now actually my preferred solution.  I have tried integrating the following into the above code, at differing locations, but cannot make headway...

     

    Search(If statement from above),Value(searchIDInput.Text), ID)

     

    The error shows 1 argument received, expecting 3 or more.  I then tried integrating the same at each option in the If statement, but again no luck.

     

    I did not keep any of the other code re sort that I have tried and so cannot replicate it here... sorry for being dull!! Regards

    Nel

  • Verified answer
    WarrenBelz Profile Picture
    156,550 Most Valuable Professional on at

    Hi @Nelwa ,

    You cannot search on Numeric columns, Search only works on Text. You need

    Search(
     AddColumns(
     SPList,
     "IDTxt",
     Text(ID)
     ),
     searchIDInput.Text
     "IDTxt"
    )

     

    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

  • Nelwa Profile Picture
    18 on at

     Hi @WarrenBelz and thanks for your answer.  It works perfectly, and I am learning more day-by-day. Thank you...😊

    Nel 

  • Nelwa Profile Picture
    18 on at

    Hi again @WarrenBelz .  Sorry to come back with another issue.  The gallery now searches and shows the data perfectly; however, I have just noticed that when I select a line to view the data via a view form (items set to Gallery.Selected) it shows no data and the app shows an error with Gallery.Selected (selected is underlined with the wavey red line).  If I remove the add columns statement, and just search on text, all works well.  Do I need to add anything to the items Gallery.Selected of my form when I integrate the add columns statement?  Thanks for your help, as ever... Nel

  • Nelwa Profile Picture
    18 on at

    Hi again @WarrenBelz 

    A little more detail, after a lot of thinking and playing!  The final items code for the Gallery becomes...

     

    Search(AddColumns(
    If(
    varRole="Pilot",
    Filter('DataSource', Pilot.Email=varUser.Email),
    Filter(
    'DataSource',
    DisplayName.Value = DropdownPilot.Selected.Value || If(
    DropdownPilot.Selected.Value = " All ",
    true,
    false
    )
    )
    ),"IDtxt",Text(ID)),searchComments_1.Text,"field_7","PilotComments","IDtxt")

     

    And the search function works perfectly, as mentioned before.

     

    Having watched a fab video by Shane Young , I realised that the items statement on the form associated with the data needs to change from Gallery1.Selected to the AddColumn statement and so I added this to the items statement for the form to view the main gallery data...

     

    AddColumns('DataSource',"IDtxt", Text(ID))

     

    But sadly the system states that there is an error in the formula, with the whole formula shown with the wavey red "line of death".  I am hoping that I am getting closer to a solution and welcome any thoughts that anyone may have.

     

    PS: I tried a Lookup solution found in other pages of this forum, but this failed as well.

     

    Thanks...Nel

  • WarrenBelz Profile Picture
    156,550 Most Valuable Professional on at

    Hi @Nelwa ,

    Try this

    Search(
     AddColumns(
     Filter(
     'DataSource', 
     (
     varRole = "Pilot" && 
     Pilot.Email=varUser.Email
     ) ||
     (
     DropdownPilot.Selected.Value = " All " || 
     DisplayName.Value = DropdownPilot.Selected.Value
     ) 
     ),
     "IDtxt",
     Text(ID)
     ),
     searchComments_1.Text,
     "field_7",
     "PilotComments",
     "IDtxt"
    )

     

    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

  • Nelwa Profile Picture
    18 on at

    Hi and thanks @WarrenBelz 

     

    I assume this code just goes into the items of the form and not the original Gallery?  

     

    When I put this in it returns the error...

     

    "Invalid Formula.  Expected a value compatible with 'DataSource'"

     

    Any idea would be gratefully received (I did add an = in the above statement varRole = "Pilot")

     

    Thank you...

    Nel

  • WarrenBelz Profile Picture
    156,550 Most Valuable Professional on at

    HI @Nelwa ,

    Yes there was a typo (now fixed), but the rest was from the code you posted - what is showing as an error - the syntax structure is correct assuming your values are.

  • Nelwa Profile Picture
    18 on at

    Thanks again @WarrenBelz 

    I have taken a couple of screenshots that show the code (just removed my unit's ID from datasource).  You will see that I have added search columns to the code.  The first is the gallery, the second the related form.  Both are the "Items" property.  The related form items shows the error... "Invalid Formula.  Expected a value compatible with 'DataSource'"

    Thanks for persevering with me Warren...

    Nel

    Gallery.png

    FormItems.png

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 397 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 354

#3
WarrenBelz Profile Picture

WarrenBelz 232 Most Valuable Professional

Last 30 days Overall leaderboard