Skip to main content
Community site session details

Community site session details

Session Id : kzAh76/rW/TaTi0KE8UVWx
Power Apps - Building Power Apps
Answered

Powerapps Gallery Search with Muliple SQL Linked Tables

Like (0) ShareShare
ReportReport
Posted on 28 Jan 2020 11:53:20 by 64

Hi,
I am having a problem with the search on gallery, I have 3 tables and I need to search by text values not ID's.
The gallery code is as follows. This is looking at the Notes field, I need to search by either employee name or vanreg.
These values are in 2 other tables, tblEmployee and tblVandetails. These tables hold the unique ID which is stored in the main table tblVanjourneyLog.
SortByColumns(Search([@'[dbo].[tblVanJourneyLog]'], TextSearchBox1.Text, "Notes"), "Notes", If(SortDescending1, Descending, Ascending))
Each field on form has a lookup field as below.
LookUp('[dbo].[Employee]',employee_id = ThisItem.EmployeeID,Concatenate(employee_fname," ",employee_sname))
I need search routine to search by either employee name or vanreg as text not ID's.

See attached table relationships, As you can see the tblVanjourneyLog is main table pulling employee details and van details from related tables.
I need to search or filter gallery by either employee ",Concatenate( employee_fname," ",employee_sname ) or Reg.
Basically when user types in text into search text box it looks for similar text in these fields. So user can type Mike and it finds Mike Morgen etc, Or
He types WA18 and finds anything associated with this reg number.
Alternatively if this is too much , need search box to search by either employee or van reg. using separate search boxes.

Thanks in advance for any help on this

Andy

 

  • Verified answer
    AndyRossco Profile Picture
    64 on 04 Feb 2020 at 11:00:09
    Re: Powerapps Gallery Search with Muliple SQL Linked Tables

    Sik,

          Thanks so much for your help and patience.

    It works now.

     

    Kind Regards

    Andy😁

  • v-siky-msft Profile Picture
    on 04 Feb 2020 at 10:41:22
    Re: Powerapps Gallery Search with Muliple SQL Linked Tables

    @AndyRossco 

    Please try this: 

    If(IsBlank(Var1),

    SortByColumns([@'[dbo].[tblVanJourneyLog]'],"EmployeeID",If(SortDescending1, Descending, Ascending)),

    SortByColumns(Filter([@'[dbo].[tblVanJourneyLog]'], EmployeeID=Var1),"EmployeeID",If(SortDescending1, Descending, Ascending)))

    Reference: https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-sort 

    Sik

  • AndyRossco Profile Picture
    64 on 04 Feb 2020 at 10:33:08
    Re: Powerapps Gallery Search with Muliple SQL Linked Tables

    Sik,
    What I will I need to change In Items code to enable this ?

    If(IsBlank(Var1), [@'[dbo].[tblVanJourneyLog]'], Filter([@'[dbo].[tblVanJourneyLog]'], EmployeeID=Var1))

    Andy

  • v-siky-msft Profile Picture
    on 04 Feb 2020 at 10:28:29
    Re: Powerapps Gallery Search with Muliple SQL Linked Tables

    @AndyRossco 

    Yes, that's right.

     

  • AndyRossco Profile Picture
    64 on 04 Feb 2020 at 10:27:24
    Re: Powerapps Gallery Search with Muliple SQL Linked Tables

    Sik,
    Ok can I sort by employeeID, This would be ok.

    Thanks in advance.

    Andy

  • v-siky-msft Profile Picture
    on 04 Feb 2020 at 10:17:19
    Re: Powerapps Gallery Search with Muliple SQL Linked Tables

    @AndyRossco 

     

    No, All sort function can only sort the original columns of Data source.

    tblVanJourneyLog only contains Employee ID and Van ID, there is no way to be sorted by Employee Name.

    Sik

  • AndyRossco Profile Picture
    64 on 04 Feb 2020 at 09:50:49
    Re: Powerapps Gallery Search with Muliple SQL Linked Tables

    Sik,

            That worked Thanks.

    Just one last thing the sort button is not working obviously since I removed the SortByColumns command from the Items code.

    Is it possible to still have sort routine within this code or the sort button

     

    If(IsBlank(Var1), [@'[dbo].[tblVanJourneyLog]'], Filter([@'[dbo].[tblVanJourneyLog]'], EmployeeID=Var1))

     

    UpdateContext({SortDescending1: !SortDescending1})

     

    Andy

  • v-siky-msft Profile Picture
    on 04 Feb 2020 at 09:10:15
    Re: Powerapps Gallery Search with Muliple SQL Linked Tables

    Ok @AndyRossco 

     

    Set the Items property of gallery as below:

    If(IsBlank(Var1), [@'[dbo].[tblVanJourneyLog]'],
    Filter([@'[dbo].[tblVanJourneyLog]'], EmployeeID=Var1))

    And append the following code to OnSelect property of Refresh icon:

    Set(Var1, Blank())

    Sik

     

  • AndyRossco Profile Picture
    64 on 04 Feb 2020 at 08:16:01
    Re: Powerapps Gallery Search with Muliple SQL Linked Tables

    Hi Sik,

               That worked to filter records by name, I now need to show all records on form load initially, then search when required. So when form loads it shows all records and when refresh will show all records also.

     

    See attached last code I entered as you suggested.

     

    Kind Regards

    Andy

  • v-siky-msft Profile Picture
    on 04 Feb 2020 at 02:28:03
    Re: Powerapps Gallery Search with Muliple SQL Linked Tables

    @AndyRossco 

     

    Employee_fname doesn't belong to 'tblVanJourneyLog' table, so the filter and SortByColumns cannot work well. 
    Please try this: 

    Filter([@'[dbo].[tblVanJourneyLog]'], EmployeeID=Var1)

    Sik

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 637 Most Valuable Professional

#2
stampcoin Profile Picture

stampcoin 570 Super User 2025 Season 2

#3
Power Apps 1919 Profile Picture

Power Apps 1919 473

Loading complete