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

Update a column in a collection with an incrementing value

Hi all,

 

Is there a way to update a column in a collection so that one row starts at a specified value (which is saved in a context variable) and then that value is incremented for the rest of the rows? I don't care which row gets which number, I just need them all to have sequential numbers. For example, the collection could start with these values:

 

17

20

50

 

If the context variable has a value of 90 then I would want to find a way to change those values to be:

 

90

91

92

 

Again, order doesn't matter, I just need those three values to be used.

 

Thanks in advance for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
Microsoft dinusc
Microsoft

Re: Update a column in a collection with an incrementing value

Hello,

 

The following example will create a copy of initial collection with updated number values.

 

Supose "aaa" is your initial collection:

ClearCollect(aaa, {val:17,name:"one"},{val:20,name:"two"},{val:50,name:"three"},{val:68,name:"four"})

 

The following should create a "bbb" collection which is idential to "aaa" but with the number columns having sequential values, starting with 90:

Clear(bbb);ForAll(aaa, Collect(bbb, {val: CountRows(bbb)+90, name:Last(FirstN(aaa, CountRows(bbb)+1)).name}))

 

You could re-assigned it back to "aaa".

View solution in original post

3 REPLIES 3
Microsoft dinusc
Microsoft

Re: Update a column in a collection with an incrementing value

Hello,

 

The following example will create a copy of initial collection with updated number values.

 

Supose "aaa" is your initial collection:

ClearCollect(aaa, {val:17,name:"one"},{val:20,name:"two"},{val:50,name:"three"},{val:68,name:"four"})

 

The following should create a "bbb" collection which is idential to "aaa" but with the number columns having sequential values, starting with 90:

Clear(bbb);ForAll(aaa, Collect(bbb, {val: CountRows(bbb)+90, name:Last(FirstN(aaa, CountRows(bbb)+1)).name}))

 

You could re-assigned it back to "aaa".

View solution in original post

Highlighted
chippman
Level: Powered On

Re: Update a column in a collection with an incrementing value

Thanks dinusc, this is perfect!

Soundjam
Level: Powered On

Re: Update a column in a collection with an incrementing value

It worked out well for my situation!

I had a gallery list (collection) that i had transposed to a checklist.  When an item was removed from the Collection, there was a gap left in the checklist because of some indexing of the collection.  This allowed me to re-index the collection into a new collection and display properly.  This will work out well when finally sending my data to an SQL database.

 

Thank you so much for this!

Cheers

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 (4,742)