cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
edhalsim
Helper II
Helper II

Update a column in a collection based on the value in that column

Hi

I have a collection as follows:

NameQuantity
Ed8
Tom3
Alan1

 

I need to update these records based on new records in a specified order:

NameQuantity
Ed-3
John13

 

So my final collection will be:

NameQuantity
Ed5
Tom3
Alan1
John13

 

I'm looping through each new row in order using a ForAll.  I don't know how to update the Quantity based on the existing Quantity, something like:

 

Patch(

    Rows,

    LookUp(

        Rows,

        Rows[@Name]=NewRow[@Name]

    ),

    {

        Quantity=Quantity+NewRow[@Quantity]

    }

)

 

Any help would be appreciated.  Thanks.

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

@edhalsim Absolutely simple!

Just have to see it from inside out.

  1. Combining the two collections, Collect(col1, col2)
  2. Grouping them on the Name as its the Key. Call this Group as "Grouped Data". The result of this will have the "Name" Column and a "Grouped Data" Column. This "Grouped Data" Column will have the Quantity for each person (E.g. it will have 2 records for Ed, 8 & -3)
  3. Add a Column called Quantity, and set its value as the Sum of the Quantity in the "Grouped Data" (E.g. for Ed, it will be Sum(8, -3) and the result is 5).
  4. Drop the "Grouped Data" Column as we don't need it any more.
  5. Store the results in another collection.
  6. Time for an Ice Cream!

Please remember to give a 👍 and accept my solution as it will help others in the future.

View solution in original post

3 REPLIES 3
CNT
Super User
Super User

@edhalsim 

Please try the following (replace collection names as applicable),

ClearCollect(colCombined, DropColumns(AddColumns(GroupBy(Collect(col1, col2), "Name", "GroupedData"), "Quantity", Sum(GroupedData, Quantity)), "GroupedData"));

 

Please remember to give a 👍 and accept my solution as it will help others in the future.

Wow.  This is beyond my current level of understanding.  Would you please explain what you're doing?

@edhalsim Absolutely simple!

Just have to see it from inside out.

  1. Combining the two collections, Collect(col1, col2)
  2. Grouping them on the Name as its the Key. Call this Group as "Grouped Data". The result of this will have the "Name" Column and a "Grouped Data" Column. This "Grouped Data" Column will have the Quantity for each person (E.g. it will have 2 records for Ed, 8 & -3)
  3. Add a Column called Quantity, and set its value as the Sum of the Quantity in the "Grouped Data" (E.g. for Ed, it will be Sum(8, -3) and the result is 5).
  4. Drop the "Grouped Data" Column as we don't need it any more.
  5. Store the results in another collection.
  6. Time for an Ice Cream!

Please remember to give a 👍 and accept my solution as it will help others in the future.

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,813)