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
PowerApps Staff CarlosFigueira
PowerApps 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':"" } ) )
2 REPLIES 2
PowerApps Staff CarlosFigueira
PowerApps 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':"" } ) )
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
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 101 members 4,159 guests
Please welcome our newest community members: