cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dhisss
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
RandyHayes
Super User
Super User

@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 below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

3 REPLIES 3
RandyHayes
Super User
Super User

@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 below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

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 🙂

RandyHayes
Super User
Super User

@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 below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (2,777)