Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
jwb3d
Frequent Visitor

Create 3 digit sequential unique key

I am new to Power BI. Currently, I have a key routine in MS Access that I am attempting to replicate in Power BI. I need to generate a sequential three-digit key for each row in a table. I am open to suggestions and hope that the example below will be helpful.

Example

keySet = Split("0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,U,V,W,X,Y,Z", ",")

KEY = 1CY

Begin with the third character in the key.

Search for the next available character in the keyset to assign to the third position. If found, replace Y with Z. FINISH.
Result: 1CZ.

If not found, the current column is "Z". Proceed to the second character in the key. You are looking for the next available character in the keyset to assign to the second position.

If found, replace C with D and set the third character in the third position to 0. Result: 1D0.

If not found, the current column is "Z". Move to the first character in the key. You are looking for the next available character in the keyset to assign to the first position.

If found, replace 1 with 2 and set the third character in the second position to 0. Result: 20Y.

2 ACCEPTED SOLUTIONS
Juan-Power-bi
Resident Rockstar
Resident Rockstar

the best way is with Power query , so your idea: your keyset has 34 characters (0-9 plus letters minus I and O). So each row just needs a sequential number converted to base-34. Add an index column in Power Query (0, 1, 2...), then convert that number to base-34 using your keyset, and pad to 3 digits.
Something like this in Power Query as a custom column:
mlet
keyset = {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z"},
n = [Index],
d1 = Number.IntegerDivide(n, 34*34),
d2 = Number.IntegerDivide(Number.Mod(n, 34*34), 34),
d3 = Number.Mod(n, 34)
in
keyset{d1} & keyset{d2} & keyset{d3}
That gives you 000 through ZZZ 

Hope it help !! 🙂

View solution in original post

ThxAlot
Super User
Super User

Hard to full understand your explanation about coding logic; but here's an elegant way to build Base10, Base16 ... sytem

let
    UDF_Digit = (digits as list, bits) =>
        if bits<=1 then digits else List.TransformMany(digits, each @UDF_Digit(digits, bits-1), (x,y) => x&y),
    Source = fx_Digit({"0".."9","A".."F"}, 3)
in
    Source

ThxAlot_0-1776118733333.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



View solution in original post

4 REPLIES 4
ThxAlot
Super User
Super User

Hard to full understand your explanation about coding logic; but here's an elegant way to build Base10, Base16 ... sytem

let
    UDF_Digit = (digits as list, bits) =>
        if bits<=1 then digits else List.TransformMany(digits, each @UDF_Digit(digits, bits-1), (x,y) => x&y),
    Source = fx_Digit({"0".."9","A".."F"}, 3)
in
    Source

ThxAlot_0-1776118733333.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



jwb3d
Frequent Visitor

I would appreciate the ability to set a starting key, as some of the keys are already in use. I would like to have the ability to set a starting key. For example:

In the database, keys 001-003 are already taken. I have captured the last used key, 003, in a separate column, and I would like to input this 'last used key' into the query. Consequently, when the query initiates, it will assign 004 to the next row. Thank you.

Juan-Power-bi
Resident Rockstar
Resident Rockstar

the best way is with Power query , so your idea: your keyset has 34 characters (0-9 plus letters minus I and O). So each row just needs a sequential number converted to base-34. Add an index column in Power Query (0, 1, 2...), then convert that number to base-34 using your keyset, and pad to 3 digits.
Something like this in Power Query as a custom column:
mlet
keyset = {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z"},
n = [Index],
d1 = Number.IntegerDivide(n, 34*34),
d2 = Number.IntegerDivide(Number.Mod(n, 34*34), 34),
d3 = Number.Mod(n, 34)
in
keyset{d1} & keyset{d2} & keyset{d3}
That gives you 000 through ZZZ 

Hope it help !! 🙂

I want to express my gratitude for this custom query. It functioned as intended. I would appreciate the ability to set a starting key, as some of the keys are already in use. I would like to have the ability to set a starting key. For example:

In the database, keys 001-003 are already taken. I have captured the last used key, 003, in a separate column, and I would like to input this 'last used key' into the query. Consequently, when the query initiates, it will assign 004 to the next row. Thank you.

 

 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.