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

create number increment items in gallery in edit mode (new).

formtotal_LI (2).jpg

The fields circled in red are from the parent table's form1, and down we have a gallery with a collection that makes dock on a child table.

I need that first field of the gallery named in the collection of "LineNItem" have a growing numbering each new line type 1, 2, 3, ... etc

as it can only be seen I was able to do repetitions of 1

@Drrickryp  could you help me?

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: create number increment items in gallery in edit mode (new).

Hi @hiranfilho ,

Do you want the first field in your Gallery to be a auto-increment number column in your "LineNItem" Collection?

Could you please share a bit more about the "LineNItem" collection that you mentioned? How many records existed within the "LineNItem" Collection?

 

Based on the needs that you mentioned, I suppose that you want to add a Index into your Collection, is it true?

 

Currently, within PowerApps, there is no direct way to add a Index value (Auto-Increment Number value, 1, 2, 3, 4, ...) into a Collection or Array. As an alternative solution, I think the Collect and AddColumns function could achieve your needs.

I have made a test on my side, please take a try with the following workaround:

Set the OnStart property of the App control or the OnVisible property of the current screen to following:

ForAll(         /* <-- Copy your original LineNItem collection data into a new collection and add a IndexValue column (growing number) */
        LineNItem,         /* <-- LineNItem represents the Collection your Gallery control connects to */
Collect(
NewCollection,
{
IndexValue: CountRows(NewCollection) + 1,
'Expense Item': LineNItem[@'Expense Item'], /* <-- 'Expense Item' and 'Expense Cost' represents the columns in your Original LineNItem collection */
'Expense Cost': LineNItem[@'Expense Cost']
}
) )

Then within your Edit screen, use the NewCollection as data source within the Gallery rather than use your Original LineNItem collection. Set the Items property of the Gallery to following:

NewCollection

within the Gallery, use the IndexValue column within the NewCollection as the first field. Set the Text property of the first Text Input box to following:

ThisItem.IndexValue

More details about adding a Index into a collection table, please check the response within the following thread:

https://powerusers.microsoft.com/t5/Creating-Apps/Numbering-rows-in-the-table/m-p/203589

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
3 REPLIES 3
Super User
Super User

Re: create number increment items in gallery in edit mode (new).

Hi @hiranfilho 

check out this thread Expressions-and-Formulas/Incrementing-Line-Number-for-PowerApps-Gallery-Rows to see If this solution can do it for you.  Unfortunately there is no single function in PowerApps that does an easy increment.

Community Support Team
Community Support Team

Re: create number increment items in gallery in edit mode (new).

Hi @hiranfilho ,

Do you want the first field in your Gallery to be a auto-increment number column in your "LineNItem" Collection?

Could you please share a bit more about the "LineNItem" collection that you mentioned? How many records existed within the "LineNItem" Collection?

 

Based on the needs that you mentioned, I suppose that you want to add a Index into your Collection, is it true?

 

Currently, within PowerApps, there is no direct way to add a Index value (Auto-Increment Number value, 1, 2, 3, 4, ...) into a Collection or Array. As an alternative solution, I think the Collect and AddColumns function could achieve your needs.

I have made a test on my side, please take a try with the following workaround:

Set the OnStart property of the App control or the OnVisible property of the current screen to following:

ForAll(         /* <-- Copy your original LineNItem collection data into a new collection and add a IndexValue column (growing number) */
        LineNItem,         /* <-- LineNItem represents the Collection your Gallery control connects to */
Collect(
NewCollection,
{
IndexValue: CountRows(NewCollection) + 1,
'Expense Item': LineNItem[@'Expense Item'], /* <-- 'Expense Item' and 'Expense Cost' represents the columns in your Original LineNItem collection */
'Expense Cost': LineNItem[@'Expense Cost']
}
) )

Then within your Edit screen, use the NewCollection as data source within the Gallery rather than use your Original LineNItem collection. Set the Items property of the Gallery to following:

NewCollection

within the Gallery, use the IndexValue column within the NewCollection as the first field. Set the Text property of the first Text Input box to following:

ThisItem.IndexValue

More details about adding a Index into a collection table, please check the response within the following thread:

https://powerusers.microsoft.com/t5/Creating-Apps/Numbering-rows-in-the-table/m-p/203589

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
hiranfilho
Level: Powered On

Re: create number increment items in gallery in edit mode (new).

Gentlemen

 

@v-xida-msft and @Drrickryp 

 

Thanks for the help, the help of @Drrickryp  opened my mind to several possibilities, but the solution of @v-xida-msft  was very simple to understand and in practice, in the Collect formula have a column that counts the line number and sums 1 was very good.

I used this in the diskette button of the form above.  My formula stayed like this:

Icon.ONSELECT:

Patch(
          ExpenseCollection;
          ThisItem;
          {
           LineNItem: Value(inputNItem.Text);
           LineItem: inputItem.Text;
           LineCost: Value(inputCost.Text)
           }
);;
Collect(
            ExpenseCollection;
            {
            LineNItem: CountRows(ExpenseCollection)+1;
            LineItem: "";
            LineCost: 0
            }
)

 

 

thank you very much

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

Users Online
Currently online: 259 members 5,291 guests
Please welcome our newest community members: