Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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).
Thanks
Solved! Go to Solution.
@Anonymous It seems simpler to me like this:
Index Column = RANKX ( Table, Table[Item],, ASC, DENSE )
Try it!
B.
@Anonymous It seems simpler to me like this:
Index Column = RANKX ( Table, Table[Item],, ASC, DENSE )
Try it!
B.
Thanks, at first glance this looks to work. I have 57k rows though so I need to make sure that its consistent.
@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
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
27 | |
10 | |
10 | |
9 | |
6 |