cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DileepGolla
Level 8

Filtering data from multiple tables

Can we filter SQL table based on the values from another table(like a join in SQL)?

 

We have two tables Table1_UserPermission["PersonID","ProjectID","IsActive"], Table2_ProjectDetails["ProjectID","ProjectName","ProjectCost"].

 

When the user logs in, we are trying to check the Table1_UserPermission table first for the active projects using the PersonID. Then project details data from Table2_ProjectDetails will be displayed in a gallery for the user active projects from Table1_UserPermission.

7 REPLIES 7
HadynM
Level 8

Re: Filtering data from multiple tables

Hi @DileepGolla

I would normally produce local collections of the active projects for the current user in Table1, and then use that to filter the list of projects in Table2.

Something like:

ClearCollect(colUserPermissions, Filter(Table1_UserPermission, PersonID=currentUserID && IsActive=true));
ClearCollect(colUserProjects, Filter(Table2_ProjectDetails, ProjectID in colUserPermissions.ProjectID))

The variable 'currentUserID' is from however you determine what the current user's ID number is.

colUserProjects becomes your Gallery.Items source.

Hope this helps.

Hadyn

DileepGolla
Level 8

Re: Filtering data from multiple tables

Hi Hadyn,

 

Thank you for taking out time and responding to my question.

 

I have tried the approach you have suggested but it gives a delagating warning when I try to use "in" operator.

 

Even if I ignore the delagation warning, the collection is empty. Are you facing the same issue? Or am I missing something obvious?

HadynM
Level 8

Re: Filtering data from multiple tables

A few things to check:

  • Is the currentUserID set to a valid ID number? (One that has 'active' projects in Table1)
  • Is there data in the colUserPermissions collection?

Cheers

Hadyn

DileepGolla
Level 8

Re: Filtering data from multiple tables

HI Hadyn,

 

Yes I can see the data collected in the first collection and also there is data in all the required columns in both the tables.

 

Thanks,

Dileep

HadynM
Level 8

Re: Filtering data from multiple tables

Hmmmm, not sure on that one.  It may be a delegation issue.

Alternatively, since you are using SQL, a stored procedure could return the results you need.  I often do this for more complicated queries with lots of joins or where there are thousands of records to filter from.

 

A step-by-step guide by @Mr-Dang-MSFT is available here:

https://powerapps.microsoft.com/en-us/blog/return-an-array-from-flow-to-powerapps-response-method/

Cheers

Hadyn

Highlighted
Community Support Team
Community Support Team

Re: Filtering data from multiple tables

Hi @DileepGolla,

Could you please share a bit more about the data structure of your two SQL tables?

Is the IsActive column a Bit type column in your Table1_UserPermission table?

Further, have you faced a Delegation Warning issue with the in operator within your formula?

I have made a test on my side, please take a try with the following workaround:

Set the OnVisible property of the first screen of your app to following:

ClearCollect(UserPermissionCollection, Filter(Table1_UserPermission, PersonID = currentUserPersonID, IsActive = true))

Set the Items property of the Gallery to following:

Filter(Table2_ProjectDetails, ProjectID in UserPermissionCollection.ProjectID)

then check if the issue is solved.

 

In addition, the in operator could be delegated within SQL table data source, please check the following article for more details:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/delegation-list

please share more details about the Delegation warning issue within your app.

As an alternative solution, in order to get rid of the Delegation warning issue, please consider take a try with the following workaround:

Set the OnVisible property of the first screen of your app to following:

ClearCollect(UserPermissionCollection, Filter(Table1_UserPermission, PersonID = currentUserPersonID, IsActive = true));
ClearCollect(ProjectDetailsCollection, Table2_ProjectDetails)

Set the Items property of the Gallery to following:

Filter(ProjectDetailsCollection, ProjectID in UserPermissionCollection.ProjectID)

 Also please check if your Table2_ProjectDetails table contains the ProjectID column, and have prorper records for current user with specific ProjectID Value.

 

In addition, 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Administrator
Administrator

Re: Filtering data from multiple tables

Thanks for creating this thread @DileepGolla. Can you review the latest replies and advise if they answer your question or if you need more assistance?

 

Thank you,

 

@TopShelf-MSFT