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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Lewdis_
Frequent Visitor

Create ID from values in column

I have a dataset with product category as one column in the product dataset. Since i have a lot of products this column is for each of them. 

 

Is there a simple way to give them and ID number from 1 to ... depending on how many unique combinations this column has?

Example Bike will be 1 Accessories 2 et

 

Category
Bikes
Accessories
Clothing
1 ACCEPTED SOLUTION
MNedix
Solution Sage
Solution Sage

Heya,

For this kind of data (e.g. Products) it is adviceable to have a dedicated table with unique values so you can easily manage relationships and other calculations. If you don't already have one, then you can create a Products table using the code below (assuming that 'Table' is your dataset table):

Products = DISTINCT(SELECTCOLUMNS('Table',"Products",'Table'[Category))

 

Then, you can simply add a calculated index column with the code:

Index = RANKX(ALL('Products'),'Products'[Products],,ASC)

 Hope it helps.

 



If the post helped then please give it a Kudos and mark it as the solution so others can see it.
Cheers,

View solution in original post

3 REPLIES 3
MNedix
Solution Sage
Solution Sage

Heya,

For this kind of data (e.g. Products) it is adviceable to have a dedicated table with unique values so you can easily manage relationships and other calculations. If you don't already have one, then you can create a Products table using the code below (assuming that 'Table' is your dataset table):

Products = DISTINCT(SELECTCOLUMNS('Table',"Products",'Table'[Category))

 

Then, you can simply add a calculated index column with the code:

Index = RANKX(ALL('Products'),'Products'[Products],,ASC)

 Hope it helps.

 



If the post helped then please give it a Kudos and mark it as the solution so others can see it.
Cheers,
anmolmalviya05
Super User
Super User

Hi @Lewdis_ , Hope you are doing good.

You can achieve this using power query editor in Power BI. 

you can assign unique IDs using Power Query.

  1. In Power BI Desktop, go to the Home tab and click Transform Data to open the Power Query editor.
  2. Select your product table. and make a dupicate of it 
  3. Select the Category column, then go to the Transform tab and click Group By.
    • In the Group By window, group by the Category column and add an operation to Count Rows. This will give you a table with the unique categories.
  4. After that, go to the Add Column tab and click Index Column to create an ID column starting from 1.
  5. Now, merge this table with your original table based on the Category column, bringing the unique IDs back into your main dataset.

 

Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!

 

Let's Connect on LinkedIn: https://www.linkedin.com/in/anmol-malviya/?originalSubdomain=in

selimovd
Super User
Super User

Hey @Lewdis_ ,

 

in Power Query there is the function of an Index column.

But you would have to match the index then also in the fact table.

 

What is your data source? It would be a lot better if you could do it there, for example in the underlying relationan database.

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍

Best regards
Denis

Blog: WhatTheFact.bi
Follow me: twitter.com/DenSelimovic
Connect with me: LinkedIn

Helpful resources

Announcements
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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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