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
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

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.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (1,659)