cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JohnMacDougall
Level: Powered On

Dynamically create a table

I know you can create a table like this:

 

 

Table({Counter: 1},{Counter: 2},{Counter: 3})

Is there a way to do this dynamically, so that if I have a variable with the value 7, it will create a table with the column Counter containing values 1,2,3,4,5,6,7?

 

 

The reason I want to do this is to loop through and collect attachements in a form connected to a SharePoint list in a dynamic way.

 

 

ForAll(Table({Counter: 1}, {Counter: 2}, {Counter: 3}), Collect(EmailAttachments, {Name:"Photo.jpg", ContentBytes: Last(FirstN(DataCardValue1.Attachments,Counter)).Value, '@odata.type':""}))

 

Then email them:

 

 

Office365.SendEmail("me@myemailaddress.com", "Hello", "Here are the photos", {Attachments: EmailAttachments})

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Dynamically create a table

There's no direct way to do that, but you can use a similar expression with FirstN to create such a table, using a table large enough for your needs. In the example below, as long as the value of the 'maxValue' variable is less than or equal to 20, then it should give you the Counter table that you need.

ForAll(
    RenameColumns(
FirstN(
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],
maxValue),
"Value",
"Counter"),
Collect( EmailAttachments, { Name:"Photo.jpg", ContentBytes: Last(FirstN(DataCardValue1.Attachments, Counter)).Value, '@odata.type':"" } ) )

View solution in original post

2 REPLIES 2
Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Dynamically create a table

There's no direct way to do that, but you can use a similar expression with FirstN to create such a table, using a table large enough for your needs. In the example below, as long as the value of the 'maxValue' variable is less than or equal to 20, then it should give you the Counter table that you need.

ForAll(
    RenameColumns(
FirstN(
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],
maxValue),
"Value",
"Counter"),
Collect( EmailAttachments, { Name:"Photo.jpg", ContentBytes: Last(FirstN(DataCardValue1.Attachments, Counter)).Value, '@odata.type':"" } ) )

View solution in original post

JohnMacDougall
Level: Powered On

Re: Dynamically create a table

Thanks. I had considered the approach of creating the table larger than needed but was wondering if a more elegant solution was possible.

Helpful resources

Announcements
thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (5,905)