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.
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
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?
A few things to check:
Cheers
Hadyn
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
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
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,
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,
@Anonymous
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.
User | Count |
---|---|
184 | |
45 | |
45 | |
34 | |
34 |
User | Count |
---|---|
257 | |
82 | |
78 | |
67 | |
65 |