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

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
LaurentN
Level: Powered On

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
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
LaurentN
Level: Powered On

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

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.
LaurentN
Level: Powered On

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.

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
New Ranks and Rank Icons in April

'New Ranks and Rank Icons in April

Read the announcement for more information!

Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (9,469)