cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Manarjomar
Resolver I
Resolver I

Create Collection from textbox adding ID

Hi there,

 

I have a collection from a text but I want to add an ID (CountRows or similar):

 

 

Collect(
    colCSVImport;
    RenameColumns(Split(Substitute(CSVImport.Text;" ";"");Char(10));"Result";"SerialCSV"))

 

 

The problem here I can't add the ID after split the text, or I don't know how do it.

 

Could someone help me?.

 

Thank you in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@Manarjomar 

The following formula will provide what you are looking for.

With({_items: Split(Substitute(CSVImport.Text;" ";"");Char(10))},
    ForAll(Sequence(CountRows(_items)),
        {SerialCSV: Last(FirstN(_items, Value)).Result,
         RowID: 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!

View solution in original post

4 REPLIES 4
RandyHayes
Super User
Super User

@Manarjomar 

The following formula will provide what you are looking for.

With({_items: Split(Substitute(CSVImport.Text;" ";"");Char(10))},
    ForAll(Sequence(CountRows(_items)),
        {SerialCSV: Last(FirstN(_items, Value)).Result,
         RowID: 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!

Hi @RandyHayes ,

 

Work well but now I will try to understand the formula.. hehehe

 

Only need to add the Collection :

 

Collect(colCSVImport;
With({_items: Split(CSVImport.Text;Char(10))};
    ForAll(Sequence(CountRows(_items));
        {SerialCSV: Last(FirstN(_items; Value)).Result;
         RowID: Value
        }
    )
))

 

Many thanks again.

RandyHayes
Super User
Super User

@Manarjomar 

Yes, the formula provided produces a table, so that can be used anywhere that you need a table.

 

It very simply does the following:

1) Creates a With Scoped Variable called _items and sets it to a table of records with a Result column produced by the Split function.

2) Then the ForAll (which is a Function that is used to Produce a table), iterates over a sequence of numbers from 1 to the count of the split records in the _items variable.

3) The second parameter of the ForAll is the record definition for records in the produced table - in this case we produce a record containing the RowID (which is just the Value of the sequence count) and the SerialCSV column - which is the result of the record at the X location in the _items table, where X is defined by the Value of the sequence count.

 

Sorry I meant to replace the commas with semicolons for your language, but forgot to! 🙄

_____________________________________________________________________________________
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!

@RandyHayes 

 

Now it's clearer, I will practice!!

 

No worries about semicolons, I understood.

 

Thank you for your time to explain me. 😉

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

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