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

Helpful resources

Announcements
firstImage

PowerApps Monthly Community Call!

Join us next Wednesday for our Demo Extravaganza, October 16, 2019 8am PDT.

firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 195 members 4,379 guests
Please welcome our newest community members: