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

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.

rand.jpg

 

 

 

 

 

 

 

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?

_powerappsID.jpg

 

 

 

 

 

 

 

 

 

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

1 ACCEPTED SOLUTION

Accepted Solutions
Power Apps Staff CarlosFigueira
Power Apps Staff

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

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.

View solution in original post

4 REPLIES 4
Power Apps Staff CarlosFigueira
Power Apps Staff

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

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.

View solution in original post

Romansx
Level: Powered On

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

how to convert hexadecimal to decimal??? @CarlosFigueira

Power Apps Staff CarlosFigueira
Power Apps Staff

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

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.

Romansx
Level: Powered On

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

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

Helpful resources

Announcements
New Ranks and Rank Icons in April

'New Ranks and Rank Icons in April

Read the announcement for more information!

Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (1,475)