cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Regular Visitor

Using a Lookup to fill a column of a collection

Hello,

 

I have to sharepoint list :

1) The first contains a list of activities done by users

  User 1; Activity 1

  User 1; Activity 2

  User 2; Activity 3

 

2) The second contains the list of all the possible activities and who is able to validate it (there are no duplicates for the activities)

  Activity 1; Validator 1

  Activity 2; Validator 2

  Activity 3; Validator 3

 

Based on this 2 sharepoint lists, I would like to create a collection containing SP list 1 with an added column containing the right validator based on the activity

 

  User 1; Activity 1; Validator 1

  User 1; Activity 2; Validator 2

  User 2; Activity 3; Validator 3

 

I am trying to us a lookup on SP 2 while populating the collection with a forall based on SP 1

 

ForAll(SP1;Collect(colwithvalidator;{User: User; Activity: Activity; Validator: Lookup(SP2;Activity = Activity;Validator)}))

The Validator field is empty when the collection is created.

 

Do you have any ideas on how to do that ?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Regular Visitor

Re: Using a Lookup to fill a column of a collection

@RandyHayes 

Hello,

 

Your formula had a small mistake but help me a lot.

 

ClearCollect(
          colWithValidator; 
          AddColumns(SP1; 
               "Validator"; Lookup(SP2; Activity=SP1[@Activity];Validator))
            )

Thank you very much 😉

View solution in original post

5 REPLIES 5
Highlighted
Super User
Super User

Re: Using a Lookup to fill a column of a collection

@LaurentN 

You might want to consider using the AddColumns function to add this information.

Try this formula out:

ClearCollect(
          colWithValidator; 
          AddColumns(SP1; 
               "Validator"; Lookup(SP2; Activity=SP1[@Activity]).Validator)
            )

That should give you what you are looking for.

 

I hope this is helpful for you.

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Highlighted
Regular Visitor

Re: Using a Lookup to fill a column of a collection

@RandyHayes 

Hello,

 

Your formula had a small mistake but help me a lot.

 

ClearCollect(
          colWithValidator; 
          AddColumns(SP1; 
               "Validator"; Lookup(SP2; Activity=SP1[@Activity];Validator))
            )

Thank you very much 😉

View solution in original post

Highlighted
Super User
Super User

Re: Using a Lookup to fill a column of a collection

@LaurentN 

Excellent!  Glad it helped.

Actually what you pointed out is not a mistake, more of a preference.  With a Lookup you can use either the Lookup(datasource; condition; columnToReturn) or Lookup(dataSource; condition).columnToReturn 

The third parameter to a Lookup is a Reduction parameter and is optional.

I happen to prefer the later...but either will work. 🙂

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Highlighted
Regular Visitor

Re: Using a Lookup to fill a column of a collection

Hello @RandyHayes ,

 

Thank you for the details and sorry to have it named a mistake. I do not remember having seen this way of using lookup in the documentation of PowerApps (the one accessible from PowerApps). Do you have something more complete to point me to ?

 

And again thank you for your great help.

Highlighted
Super User
Super User

Re: Using a Lookup to fill a column of a collection

@LaurentN 

Nothing more complete to point to.  As for the docs, they mention the "reduction" parameter, which is optional and state that if not specified, then the record is the result.  Somewhere along the line in looking at so many apps, the (dot) property syntax seemed to rule.  For me personally, it was very similar to development of code...so it fit!

 

Sometimes it's a preference, and sometimes it is needed.

If a single column value is all you need from at Lookup, then the reduction parameter is sufficient.  

In other cases, you might need the full record (as in the case of assigning to a variable or using in another formula), in which case the Lookup without the reduction parameter is required.

 

I hope that is clear and helpful.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

Helpful resources

Announcements
Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,114)