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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
naga449
Frequent Visitor

Adding Serial Number using DAX(Not in Transform data)

Hi Community,

 

Could you please help me with this,

 

I have a Dim Table with countries,

Country
India
Australia
South America
North America
Japan
Germany

I want to sort this in the column as it is in a table, so I need to add index or sequence numbers to this table USING DAX Only.

 

Please help with this.

 

Thanks 

Naga Karthik.

4 REPLIES 4
Stachu
Community Champion
Community Champion

you could use something like this:

Index = 
SWITCH('Countries'[Country],
"India",0,
"Australia",1,
"South America",2,
"North America",3,
"Japan",4,
"Germany",5
)

but althouth it will work, this is a bad practice. How is this table sourced, and what is the logic of the order? Or is it completely arbitrary?



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

@Stachu 

 

You realize that this is totally unmaintainable unless... he has a list of all countries in the world?

Definitely, doing this in the Power Query/source should be the way to go, that's why I said it is a bad practice. But considering that some of the items are South America and North America I do not expect the list to be extremely long.



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

daxer-almighty
Solution Sage
Solution Sage

You can't do this in DAX alone. Sorry, you're out of luck. The only sort that DAX obeys natively is the alphabetical order of strings and the natural order of numbers/date(time)s (date(time)s are numbers in disguise). To have a different sort than the mentioned ones you have to create a column and manually insert the numbers by which you want to sort the column. This is best done either in PQ (using Add Column) or outside the system in some ETL layer or in the source.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.