cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PowerApps11
Helper IV
Helper IV

Auto genarate invoice number

Hello,

Is there a way i can generate invoice number when clicked create new record using a form from Sharepoint Data Source?
here a is what i need an example format

Capture11.JPG
Thanks 

2 ACCEPTED SOLUTIONS

Accepted Solutions
365-Assist
Power Participant
Power Participant

The easiest way to is to use the ID Column in SharePoint. It will autoincrement for every record.

365Assist_0-1656635261351.png

 

However, If you prefer to control a number in Power Apps you can do it this way.

1 - Create a Number Column in SharePoint.

365Assist_1-1656635327803.png

2 - In Power Apps Create a Collection (App -> OnStart). You may need to do this as you could hit Delegation warnings if you use the column in SP directly.

365Assist_2-1656635412524.png

ClearCollect(colInvoiceNumber,'Demo List'.'Invoice Number')

 

3 - Get the last Invoice Number an add 1.

365Assist_3-1656635548898.png

Sum(Max(colInvoiceNumber,'Invoice Number')+1)

---------------------------------------------------
Please Accept as Solution if it solves your question. Or just give it a Thumbs Up if it is helpful as can help others.

Subscribe: https://www.youtube.com/channel/UCFpvUlpx84FuIPOdInGKMTw
Twitter: https://twitter.com/assist_365

Regards
Darren Lutchner - 365 Assist

View solution in original post

Drrickryp
Super User
Super User

@PowerApps11 

Much better is First(Sort,ID,Descending)).ID+1

The other methods using Max() and Last() will become inaccurate beyond 2k items due to delegation issues. First(Sort... Will work no matter how many records are in the list.

View solution in original post

4 REPLIES 4
365-Assist
Power Participant
Power Participant

The easiest way to is to use the ID Column in SharePoint. It will autoincrement for every record.

365Assist_0-1656635261351.png

 

However, If you prefer to control a number in Power Apps you can do it this way.

1 - Create a Number Column in SharePoint.

365Assist_1-1656635327803.png

2 - In Power Apps Create a Collection (App -> OnStart). You may need to do this as you could hit Delegation warnings if you use the column in SP directly.

365Assist_2-1656635412524.png

ClearCollect(colInvoiceNumber,'Demo List'.'Invoice Number')

 

3 - Get the last Invoice Number an add 1.

365Assist_3-1656635548898.png

Sum(Max(colInvoiceNumber,'Invoice Number')+1)

---------------------------------------------------
Please Accept as Solution if it solves your question. Or just give it a Thumbs Up if it is helpful as can help others.

Subscribe: https://www.youtube.com/channel/UCFpvUlpx84FuIPOdInGKMTw
Twitter: https://twitter.com/assist_365

Regards
Darren Lutchner - 365 Assist

Drrickryp
Super User
Super User

@PowerApps11 

Much better is First(Sort,ID,Descending)).ID+1

The other methods using Max() and Last() will become inaccurate beyond 2k items due to delegation issues. First(Sort... Will work no matter how many records are in the list.

PowerApps11
Helper IV
Helper IV

Hi @365-Assist and @Drrickryp 
I have Sorted using this formula and tested on 10000 list and worked nicely getting me last ID also Drrickryp you right about will become inaccurate beyond 2k items due to delegation issues and am not a fun of collection 😡 as it would make, you're apps go very slow, actually all my apps are delegation free while filtering and getting what I need beyond 2k items including dates. 🤣   

"Invoice # " &Text(First(FirstN(Sort(Test,ID,Descending),1)).ID+1,"[$-en-US]000500000")

CaptureAc.PNG
SharePoint
CaptureSharepoint.PNG


Thanks again both

@Drrickryp 
Is there a way to autoincrement the ID if saving bulk like multiple items? when patching?

Text(First(FirstN(Sort(Test,ID,Descending),1)).ID+1,"[$-en-US]000500000")

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,802)