web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Generating a random in...
Power Apps
Answered

Generating a random invoice number

(0) ShareShare
ReportReport
Posted on by 332

Hello all -

 

I need to generate a completely random invoice number in an app, and I've found a formula that works:

 

Right(Text(Rand()*10),3)&"-"&Right(Text(Rand()*10),3)

 

However, I'm not sure how to keep the number from recalculating every time my form is submitted. Once this number is generated it needs to remain associated with its item, and never change.

 

Any ideas would be greatly appreciated. Thanks!

Categories:
I have the same question (0)
  • Silvester. Akakpo Profile Picture
    783 on at

    Hi @T_A_M ,
    Kindly try setting it up the value in a variable 

    Set(VarInvoiCceNum, Right(Text(Rand()*10),3)&"-"&Right(Text(Rand()*10),3))

    You can attach the variable to the record while submitting the form.

  • Verified answer
    Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @T_A_M 

    No need to use a variable. Set the Text property of the InvoiceNumber control to 

    Coalesce(Parent.Default,Right(Text(Rand()*10),3)&"-"&Right(Text(Rand()*10),3)), When the form is in new mode, the Parent.Default will be blank and then your formula will generate a random invoice number.  When the form is in edit mode, the already assigned random invoice number will be the Parent.Default and a new number will not be generated.  I would set the Display property of the card containing the invoice number to disabled to prevent users from changing it or trying to assign one. 

  • T_A_M Profile Picture
    332 on at

    Thank you! That worked perfectly.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 379 Most Valuable Professional

#2
11manish Profile Picture

11manish 203 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 128 Super User 2026 Season 2

Last 30 days Overall leaderboard