cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
martinav
Super User
Super User

Add sequence to an existing collection. Aribitrarily.

Given:
varStartSequence: 12345

Collection: MyCollection

 

Desired Output: 

MyCollection with an additional column that contains a numeric sequence starting with 12345.  This is what I'm thinking.  (Syntax broken, but logic is there)

 

 

With({IDSequence: Sequence(CountRows(MyCollection), varStartSequence)},
    ForAll(IDSequence As IDn, AddColumns(MyCollection,"ID", IDn.Value))
)

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Oh wait... since varStartSequence does not start at one, Value needs offset.  I changed to this, and it worked.

 

 

ForAll(Sequence(CountRows(MyCollection), varStartSequence),
    Patch(Last(FirstN(MyCollection, Value-varStartSquence)), {IDSequence:Value})
)

 

View solution in original post

5 REPLIES 5
RandyHayes
Super User
Super User

@martinav 

Please consider changing your Formula to the following:

ForAll(Sequence(CountRows(MyCollection), varStartSequence),
    Patch(Last(FirstN(MyCollection, Value)), {IDSequence:Value})
)

 

I hope this is helpful for you.

_____________________________________________________________________________________
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.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

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

Hi @martinav ,

Here is the process from a blog of mine (used for shading alternate rows in galleries)

 

EDIT - I see @RandyHayes beat me to it please accept his.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

 

 

RandyHayes
Super User
Super User

@WarrenBelz 

That one is a lot like my video on the same process😂  Except the ForAll used as it was designed 😁  I don't know why everyone wants to use those backwards! 

 

_____________________________________________________________________________________
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.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

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

I'm just a little confused.  This seems to result in n rows of just one item in MyCollection.  

 

Where = CountRows(MyCollection)

Oh wait... since varStartSequence does not start at one, Value needs offset.  I changed to this, and it worked.

 

 

ForAll(Sequence(CountRows(MyCollection), varStartSequence),
    Patch(Last(FirstN(MyCollection, Value-varStartSquence)), {IDSequence:Value})
)

 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (3,080)