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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
TB123
Employee
Employee

ID column where a new row receives a new ID

Hi,

 

I am trying to create an ID column (like an index column), where if a new row is added to the table, it receives a new index number (ID).

The problem I'm having with creating an index column is that if I were to add a new country, in this case France, in the source file, then it just joins the index and takes an existing number (see example below):

Original:                                                                                  

                                                                                                  TB123_0-1642679485716.png

 

 

 

 

 

 

 

New (Wrong):

TB123_2-1642679676047.png

France has taken Italy's number of 4, whereas I want it to say 7.

As I'm using this colunm to join to other tables, it has to be fixed and the numbers can't move around when a new row is added.

 

Any help would be much appreciated.

 

3 REPLIES 3
v-angzheng-msft
Community Support
Community Support

Hi, @TB123 

Always adding new countries at the bottom of the table will solve your problem.

You can also create a country dimension table and then create a custom function to find and replace the index. This helps you to replace the index of the newly added country. Refer to the thread below to create the function.

Replacing values in one column with values from another table

 

 

Best Regards,
Community Support Team _ Zeon Zheng


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

mahoneypat
Employee
Employee

Two approaches you can consider:

1. Make your index/countryID columns dynamic across all your tables, if possible, so even if they change they are correct.

2. Add a date added column somehow to your country table and then use Table.Buffer(Table.Sort()) to sort it by that new column prior to adding the index column.

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thanks for the reply Pat.

How would I got about adding a date added column?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors