cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MichaB12
Helper I
Helper I

Strange behaviour with Patch, AddColumns and nested tables

Hi,

 

I have 2 collections, c1 just contains values, and c2 is the result of a groupBy of b column of c1:

ClearCollect(c1, {a:1, b:1}, {a:2, b:1}, {a:3, b:3}, {a:4, b:1});
ClearCollect(c2, GroupBy(c1,"b", "rest"))

 

So in the c2 collection we have 2 columns:

  • "b" which contains a value
  • "rest" which contains a single column table named "a"

 

Let's say I want to update the first row of c2, I want to add a new column to the table in the "rest" column.

 

I tried to construct this new table elsewhere like this and it worked well:

AddColumns(First(c2).rest, "test", true)

 

But when I want to apply the changes to c2 with Patch it doesn't work:

Patch(c2, First(c2), {b:-1, rest:AddColumns(First(c2).rest, "test", true)})

 

Event stranger, I can change the "b" column value without any problem. So there is probably something I am missing with tables. Could anyone explain me what I don't understand here? Why is the table not changed in c2 collection?

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User III
Super User III

@MichaB12 

You cannot change the schema like that in a table column of a collection table.  Schema is highly important in PowerApps.

 

What is it that you are trying to achieve?  This is very "programmatic" from what it appears - Keep in mind, PowerApps is modeled after Excel - it is not a development platform.

 

_____________________________________________________________________________________
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.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

View solution in original post

3 REPLIES 3
RandyHayes
Super User III
Super User III

@MichaB12 

You cannot change the schema like that in a table column of a collection table.  Schema is highly important in PowerApps.

 

What is it that you are trying to achieve?  This is very "programmatic" from what it appears - Keep in mind, PowerApps is modeled after Excel - it is not a development platform.

 

_____________________________________________________________________________________
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.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

View solution in original post

MichaB12
Helper I
Helper I

Oh I didn't know that... Thanks! 

 

Well with that in mind I managed to add this column at the creation of the main table. I used a groupBy to create this nested table, so I just added the AddColumns before the GroupBy and now I don't need to add this column later 🙂 

 

Thank you for your reply!

 

RandyHayes
Super User III
Super User III

@MichaB12 

Yes, that is exactly what to do.  You need to define the schema from the very start.  Note that this is relevant to "modifying" an existing table.  You can derive new tables from existing with modified column - this is what shaping data is all about.  But, once you define the schema, it is what is referenced and used - and "set".

_____________________________________________________________________________________
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.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Carousel April Dunnam Updated 768x460.jpg

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

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