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

Lookup inside patch and forAll, result all the same

Hi, I'm new in powerapps
can somebody help me 

I try to make a collection with using lookup another collection to make value if it finds specific id 
But the result is not what I expected. It result all the row in column "return" is same, 
Even if I check it one by one, it should be different 

Capture.PNGCapture.PNG

If I check from other collection 
it should be:

returnable
returnable
returnable
Non Returnable
Non Returnable
Non Returnable
Non Returnable


is my script wrong when using lookup from different collection?

1 ACCEPTED SOLUTION

Accepted Solutions
Super User III
Super User III

@dhisss 

Your trouble comes from the item_code=item_code.  This will always return a true and thus you will get the first record in item_col all the time.

 

Consider the following formula to replace yours:

Clear(nd6_stockReport);

With({_user: LookUp(user, email=User().Email},
    ForAll(
        nd6_standart as _nd6,
        Patch(nd6_stockReport,
            Defaults(nd6_stockReport),
            {
                month:Text(_nd6.month_stockcount),
                region: _user.region,
                ship_to: _user.code,
                distributor: _user.name,
                return: _user.return,
                item_code: LookUp(item_col, item_code = _nd6.item_code, return),
                item_name: _nd6.item_name,
                main_stokSistem: Value(_nd6.mainstokSistem)
            }
         )
    )
);
Navigate(distributor_home)

 

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.
Check out my PowerApps Videos too!

View solution in original post

3 REPLIES 3
Super User III
Super User III

@dhisss 

Your trouble comes from the item_code=item_code.  This will always return a true and thus you will get the first record in item_col all the time.

 

Consider the following formula to replace yours:

Clear(nd6_stockReport);

With({_user: LookUp(user, email=User().Email},
    ForAll(
        nd6_standart as _nd6,
        Patch(nd6_stockReport,
            Defaults(nd6_stockReport),
            {
                month:Text(_nd6.month_stockcount),
                region: _user.region,
                ship_to: _user.code,
                distributor: _user.name,
                return: _user.return,
                item_code: LookUp(item_col, item_code = _nd6.item_code, return),
                item_name: _nd6.item_name,
                main_stokSistem: Value(_nd6.mainstokSistem)
            }
         )
    )
);
Navigate(distributor_home)

 

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.
Check out my PowerApps Videos too!

View solution in original post

huwaaa, Thank you so much @RandyHayes 
it works! although you misplace some codes, but I understand the concept and make it works

Thanks, I also learn how to use "with", and "as" in this powerapps
I don't know about it before 🙂

Super User III
Super User III

@dhisss 

Yes, I see at least two typos now in the formula.  I do type these all by hand, so I don't get the luxury of the Formula Editor to help 😉

 

I am glad that this worked for you and that you learned a couple of things.

_____________________________________________________________________________________
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.
Check out my PowerApps Videos too!

Helpful resources

Announcements
News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

Power Apps Community Call

Power Apps Community Call- January

Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

Top Solution Authors
Top Kudoed Authors
Users online (11,509)