cancel
Showing results for
Did you mean:
Helper II

## Manually Generating UniqueId Key Values, or how is it generated, use __PowerAppsId__?

My spreadsheets all have generated a Unique_ID with following formula.

`  =DEC2HEX(RANDBETWEEN(0,4294967295),8)`

But in powerapps it only has the RAND () function.

How to generate unique_Id as the formula =DEC2HEX(RANDBETWEEN(0,4294967295),8) - in Excel it works.

No need to change my environment and application.

Would you have to generate UNIQUE_ID in an external environment?

Or how is the __PowerAppsId__ ID generated? What is the function?

Because even generating an extra column in my application, I could not access it in PowerApps.

1 ACCEPTED SOLUTION

Accepted Solutions
Power Apps

PowerApps doesn't have a way to (directly) convert a number into its hexadecimal form, nor has it a direct map to the RANDBETWEEN function in Excel. But there are ways around it...

For RANDBETWEEN, you can use the RoundDown and Rand functions. If you want to have an expression equivalent to

`RANDBETWEEN(low, high)`

You can use the following expression in PowerApps:

`low + RoundDown((high - low + 1) * Rand(), 0)`

For example, to get a number between 10 and 20 (inclusive), you can use this in PowerApps:

`10 + RoundDown(11 * Rand(), 0)`

PowerApps does not have an equivalent to DEC2HEX - converting arbitrary numbers to hexadecimal (you can create a new item in the PowerApps ideas board for that to be added to the backlog). We can, however, use the Mid function to convert a single-digit hexadecimal number, and we can use that to create your 8-digit random hexadecimal id:

```Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1)```

It works, but I certainly undestand that it's not pretty, so feel free to create the new feature request in the ideas board.

5 REPLIES 5
Power Apps

PowerApps doesn't have a way to (directly) convert a number into its hexadecimal form, nor has it a direct map to the RANDBETWEEN function in Excel. But there are ways around it...

For RANDBETWEEN, you can use the RoundDown and Rand functions. If you want to have an expression equivalent to

`RANDBETWEEN(low, high)`

You can use the following expression in PowerApps:

`low + RoundDown((high - low + 1) * Rand(), 0)`

For example, to get a number between 10 and 20 (inclusive), you can use this in PowerApps:

`10 + RoundDown(11 * Rand(), 0)`

PowerApps does not have an equivalent to DEC2HEX - converting arbitrary numbers to hexadecimal (you can create a new item in the PowerApps ideas board for that to be added to the backlog). We can, however, use the Mid function to convert a single-digit hexadecimal number, and we can use that to create your 8-digit random hexadecimal id:

```Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1) &
Mid("0123456789ABCDEF", 1 + RoundDown(Rand() * 16, 0), 1)```

It works, but I certainly undestand that it's not pretty, so feel free to create the new feature request in the ideas board.

how to convert hexadecimal to decimal??? @CarlosFigueira

Power Apps

There's no simple formula for that (please consider creating a new feature request in the PowerApps Ideas board for that, I'd certainly vote it up), but you can use the expression below:

```Sum(
FirstN([1,2,3,4,5,6,7,8,9,10],Len(TextInput1.Text)),
Power(16, Len(TextInput1.Text) - Value) *
(Find(Mid(TextInput1.Text, Value, 1), "0123456789ABCDEF") - 1))```

This will work for hexadecimal numbers of up to 10 digits (if you want more, you can increase the table size in the FirstN function), for upper-case digits A-F only (if you also want to support lowercase ones, use the Upper function to convert the text to uppercase), and for valid values (if you have invalid characters - i.e., those outside of the [0-9][A-F] range - then it will give you an incorrect result).

The idea behind that formula is to take the input, break it down in individual characters, and multiply their value by the corresponding power of 16. The attached app shows this expression in action, feel free to download it and play around with it to learn more.

Great! @CarlosFigueira thanks and when find free time will post the idea!
Anonymous
Not applicable

Hi, do yall know how to generate a unique id like a,b,c once button is clicked.

The delivery id generated will be used in another sharepoint list.

The id column used is Delivery_ID.

How to amend the codes below? Thanks.

SendEmailv2.Run(JSON(colOrderItems));

// insert new row for each product into SharePoint list
ForAll(
colOrderItems,
Patch(
OrderList,
Defaults(OrderList), {
Memory: Memory,
Storage: Storage,
Title: Title,
Quantity: Value(Quantity),
Price: Value(Price),
'TotalPrice (TotalPrice0)': TotalPrice,
Image: Image,
Dept: Dept,
Division: Division,
DeliverLocation: DeliverLocation,
'28ByteCode': '28 Byte Code',
Product: ProductFinal,
Processor: Processor,
Remarks: Remarks
}
)
);

Notify("Order was successfully submitted", NotificationType.Success);

Announcements

#### Back to Basics Tuesday Tip #9: All About the Galleries

This is the ninth post in our series dedicated to helping the amazing members of our community--both new members and seasoned veterans--learn and grow in how to best engage in the community! Each Tuesday, we feature new content that will help you best understand the community--from ranking and badges to profile avatars, from Super Users to blogging in the community. Our hope is that this information will help each of our community members grow in their experience with Power Platform, with the community, and with each other!     Today's Tip: All About the Galleries Have you checked out the library of content in our galleries? Whether you're looking for the latest info on an upcoming event, a helpful webinar, or tips and tricks from some of our most experienced community members, our galleries are full of the latest and greatest video content for the Power Platform communities.   There are several different galleries in each community, but we recommend checking these out first:   Community Connections & How-To Videos Hosted by members of the Power Platform Community Engagement  Team and featuring community members from around the world, these helpful videos are a great way to "kick the tires" of Power Platform and find out more about your fellow community members! Check them out in Power Apps, Power Automate, Power Pages, and Copilot Studio!         Webinars & Video Gallery Each community has its own unique webinars and videos highlighting some of the great work being done across the Power Platform. Watch tutorials and demos by Microsoft staff, partners, and community gurus! Check them out: Power Apps Webinars & Video Gallery Power Automate Webinars & Video Gallery Power Pages Webinars & Video Gallery Copilot Studio Webinars & Video Gallery   Events Whether it's the excitement of the Microsoft Power Platform Conference, a local event near you, or one of the many other in-person and virtual connection opportunities around the world, this is the place to find out more about all the Power Platform-centered events. Power Apps Events Power Automate Events Power Pages Events Copilot Studio Events   Unique Galleries to Each Community Because each area of Power Platform has its own unique features and benefits, there are areas of the galleries dedicated specifically to videos about that product. Whether it's Power Apps samples from the community or the Power Automate Cookbook highlighting unique flows, the Bot Sharing Gallery in Copilot Studio or Front-End Code Samples in Power Pages, there's a gallery for you!   Check out each community's gallery today! Power Apps Gallery Power Automate Gallery Power Pages Gallery Copilot Studio Gallery