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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
tksnota01
Frequent Visitor

Create A Calculated Column With Number for Unique Text

Hi,

 

I have hundred of names and I need to create numbers to represent each of them as shown 

 

Are there DAX or M Code I can use?

 

Thanks...tksnota01...

 

A 1
B 2
C 3
D 4

B 2

D 4

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

In Power Query make  a copy of your existing table and remove all the columns except the name. Remove duplicate values then add an index column, then use Merge as new to merge the original query with the list of unique names. Expand the merged table to bring in the index column.

Finally, you can untick the Enable Load option for the original query and the unique names, so only the merged table is pulled into your model.

View solution in original post

3 REPLIES 3
Cookistador
Super User
Super User

The following calculated column should work

 

NameRank =

RANKX(
DISTINCT('Table'[Name]), 
CALCULATE(MIN('Table'[Name])), 
, ASC, DENSE 
)

johnt75
Super User
Super User

In Power Query make  a copy of your existing table and remove all the columns except the name. Remove duplicate values then add an index column, then use Merge as new to merge the original query with the list of unique names. Expand the merged table to bring in the index column.

Finally, you can untick the Enable Load option for the original query and the unique names, so only the merged table is pulled into your model.

lbendlin
Super User
Super User

In M group by the name (and keep the rows), add an index column, and then expand the rows back out.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors