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

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
Super User

@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

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

@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

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

View solution in original post

MichaB12
Helper II
Helper II

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
Super User

@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

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

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (3,542)