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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Unique value Index (duplicates are same)

How would I create a unique value index with Dax code? I am in the process of creating a ragged heirachy using a Tabular model so it has to be done using DAX code (I can't use PQ, etc). What I am looking for is a column which will assign an index for each instance where the item is distinct. If it is duplicated on another row I want it to be assigned the same index (as shown in the picture).

DaxUser101_1-1632340920454.png

 

Thanks

 

1 ACCEPTED SOLUTION
BeaBF
Super User
Super User

@Anonymous It seems simpler to me like this:

Index Column = RANKX ( Table, Table[Item],, ASC, DENSE )

 

Try it!

B.

View solution in original post

3 REPLIES 3
BeaBF
Super User
Super User

@Anonymous It seems simpler to me like this:

Index Column = RANKX ( Table, Table[Item],, ASC, DENSE )

 

Try it!

B.

Anonymous
Not applicable

Thanks, at first glance this looks to work. I have 57k rows though so I need to make sure that its consistent.

Greg_Deckler
Community Champion
Community Champion

@Anonymous Indexes in DAX are not particularly easy and were once thought impossible. Hard to guarantee any sort of sort order, not that I see what sort order you would want. You can try this:

Column = 
  VAR __Item = [Item]
  VAR __Text = CONCATENATEX('Table',[Item],"|")
  VAR __Count = PATHLENGTH(__Text)
  VAR __Table = 
    ADDCOLUMNS(
      GENERATESERIES(1,__Count,1),
      "__Item",PATHITEM(__Text,[Value])
    )
  VAR __TableFinal = 
    SUMMARIZE(__Table,[__Item],"Index",MINX(FILTER(__Table,[__Item]=EARLIER([__Item])),[Value]))
RETURN
  MINX(FILTER(__TableFinal,[__Item] = __Item),[Index])

Original concept is from The Mythical DAX Index: (2) The Mythical DAX Index - Microsoft Power BI Community

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.