cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
sandra1
Level: Powered On

Join the same table

Hello,

 

I have one table friendship that has two columns: person_id_1  and person_id_2. 

The relation is unidirectional, so person A cound be a friend of person B even if person B is no friend of person A. 

Now I want to filter only "true friends" (where the friendship is bidirectional)  in my Powerapps gallery. 

In SQL I would do something like this: 

 

SELECT a.person_id_1, a.person_id_2

FROM friendship a, (SELECT person_id_2, person_id_1 FROM friendship) b

WHERE a.person_id_1=b.person_id_2 and a.person_id_2=a.person_id_1;

 

I'm not sure how to do this in Powerapps. I think I need a "join" (or in Powerapps AddColumns) on the same table. 

Has anyone a idea how to do this? 

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Community Support Team
Community Support Team

Re: Join the same table

Hi @sandra1 ,

Based on the needs that you mentioned, I think the ForAll function and Collect function could achieve your needs. I have made a test on my side, please consider take a try with the following workaround:

Add a button in your app, set the OnSelect property to following:

Clear(TrueFriends);
ForAll(
       RenameColumns('[dbo].[friendship]', "person_id_1", "personA", "person_id_2", "personB"),
       If(
          !IsBlank(LookUp('[dbo].[friendship]', person_id_1 = personB && person_id_2 = personA)),
          Collect(
                   TrueFriends, 
                   {
                       PersonA: person_id_1, 
                       PersonB: person_id_2
                   }
         )
       )
)

Then you could add a Data Table control within your app, set the Items property to following:

TrueFriends

then enable the PersonA field and PersonB field within the Data Table, after you press the button control, then you could see the true friends within your friendship table.

 

Please take a try with above solution, check if the issue is solved.

 

Best regards,

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.

View solution in original post

Community Support Team
Community Support Team

Re: Join the same table

Hi @sandra1 ,

Yeah, you are right. The ForAll function is not a delegable function in PowerApps currently. Based on the needs that you mentioned, if you want to achieve your needs using Delegable functions, I afraid that there is no way to achieve your needs.

 

As an alternative solution, if you want to improve your formula's performace in your app, I think the collection could achieve your needs. You could consider save your SQL Table records into a collection, then use the collection as data source in your app.

 

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

Set the OnStart property of App to following:

ClearCollect(SQLTableRecords, '[dbo].[friendship]')

Add a button in your app, set the OnSelect property to following:

Clear(TrueFriends);
ForAll(
       RenameColumns(SQLTableRecords, "person_id_1", "personA", "person_id_2", "personB"),
       If(
          !IsBlank(LookUp('[dbo].[friendship]', person_id_1 = personB && person_id_2 = personA)),
          Collect(
                   TrueFriends, 
                   {
                       PersonA: person_id_1, 
                       PersonB: person_id_2
                   }
         )
       )
)

Please take a try with above solution, then re-load your app (fire the OnStart property of App), then check if the issue is improved.

 

Best regards,

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.

View solution in original post

4 REPLIES 4
Dual Super User
Dual Super User

Re: Join the same table

Hey @sandra1 

 

You can use the below expression as:

AddColumns(Filter(GroupBy(AddColumns(Friendship,"Columns",Concat(Sort([person_id_1,person_id_2],Value,Ascending),Value)),"Columns","Grouped"),CountRows(Grouped) = 2),"Person_1",Last(Grouped).person_id_1,"Person_2",Last(Grouped).person_id_2)

Here, a custom column "Columns" is created to check the same value for the Person1 and Person2 column. As part of this query, you can access Person1 name using ThisItem.Person_1 and Person 2 as ThisItem.Person_2.

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Community Support Team
Community Support Team

Re: Join the same table

Hi @sandra1 ,

Based on the needs that you mentioned, I think the ForAll function and Collect function could achieve your needs. I have made a test on my side, please consider take a try with the following workaround:

Add a button in your app, set the OnSelect property to following:

Clear(TrueFriends);
ForAll(
       RenameColumns('[dbo].[friendship]', "person_id_1", "personA", "person_id_2", "personB"),
       If(
          !IsBlank(LookUp('[dbo].[friendship]', person_id_1 = personB && person_id_2 = personA)),
          Collect(
                   TrueFriends, 
                   {
                       PersonA: person_id_1, 
                       PersonB: person_id_2
                   }
         )
       )
)

Then you could add a Data Table control within your app, set the Items property to following:

TrueFriends

then enable the PersonA field and PersonB field within the Data Table, after you press the button control, then you could see the true friends within your friendship table.

 

Please take a try with above solution, check if the issue is solved.

 

Best regards,

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.

View solution in original post

sandra1
Level: Powered On

Re: Join the same table

Hey @v-xida-msft,

Thank you very much for your answer. Your solution works, but it's really slow. I have a list of 5 people and 3 "real friends" and it took about 2 seconds for the data to load. 

Yesterday I tried the same with a database view and it was much faster. 

So I think your solution is not delegable (I think the for all statement is executed by powerapps. Isn't it? ) 

Do you know a solution that is delegable? 

@yashag2255 I tried your solution, but I got a lot of bugs and couldn't get it to work. 

 

Community Support Team
Community Support Team

Re: Join the same table

Hi @sandra1 ,

Yeah, you are right. The ForAll function is not a delegable function in PowerApps currently. Based on the needs that you mentioned, if you want to achieve your needs using Delegable functions, I afraid that there is no way to achieve your needs.

 

As an alternative solution, if you want to improve your formula's performace in your app, I think the collection could achieve your needs. You could consider save your SQL Table records into a collection, then use the collection as data source in your app.

 

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

Set the OnStart property of App to following:

ClearCollect(SQLTableRecords, '[dbo].[friendship]')

Add a button in your app, set the OnSelect property to following:

Clear(TrueFriends);
ForAll(
       RenameColumns(SQLTableRecords, "person_id_1", "personA", "person_id_2", "personB"),
       If(
          !IsBlank(LookUp('[dbo].[friendship]', person_id_1 = personB && person_id_2 = personA)),
          Collect(
                   TrueFriends, 
                   {
                       PersonA: person_id_1, 
                       PersonB: person_id_2
                   }
         )
       )
)

Please take a try with above solution, then re-load your app (fire the OnStart property of App), then check if the issue is improved.

 

Best regards,

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.

View solution in original post

Helpful resources

Announcements
thirdimage

Power Apps Community User Group Member Badge

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

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Kudoed Authors (Last 30 Days)
Users online (3,675)