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

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

Reply
Anonymous
Not applicable

Adding index in a calculated table for sorting purposes

Hi everyone!

 

I've used the solution on adding total to a clustered chart from this thread and it worked perfectly. The only thing is that the order of columns is not OK now (see the picture below). Should be 0-2, 3-5, 6-12, etc.

 

Can anyone advise on how to add an index column to the calculated table 'Table', so I can sort the order of tenure categories on my chart properly?

 

Thanks.

 

Снимок экрана (9).png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

One way is to add the calculated column to tooltips filed of the visual as @tex628 mentioned and click "..." on the visual then sort by calculated column.

15.PNG

16.PNG

Another way is create a custom column in Query Editor and sort the column1 by the custom column (no need to add custom column to tooltips field).

17.PNG

18.PNG

19.PNG

But as you said your table is a calculated table so the second way is not suitable for your current scenario but you might use it someday😁

 

Best Regards,

Jay

Community Support Team _ Jay Wang

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

 

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Hi @Anonymous ,

 

One way is to add the calculated column to tooltips filed of the visual as @tex628 mentioned and click "..." on the visual then sort by calculated column.

15.PNG

16.PNG

Another way is create a custom column in Query Editor and sort the column1 by the custom column (no need to add custom column to tooltips field).

17.PNG

18.PNG

19.PNG

But as you said your table is a calculated table so the second way is not suitable for your current scenario but you might use it someday😁

 

Best Regards,

Jay

Community Support Team _ Jay Wang

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

 

Anonymous
Not applicable

Thanks @tex628, @Anonymous!

 

Anonymous
Not applicable

Hi @Anonymous ,

 

Depending on your data and needs you can use SWITCH() function, IF() function or RANKX() function to create a new column and sort by this column.

switch = SWITCH('Table'[Column1],"0-2",1,"3-5",2,"6-12",3)

if = IF('Table'[Column1]="0-2",1,IF('Table'[Column1]="3-5",2,3))

rank = RANKX('Table','Table'[Column1],,ASC)

1.PNG 

 

Best Regards,

Jay

Community Support Team _ Jay Wang

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

 

Anonymous
Not applicable

Hi @Anonymous,

 

Thanks a lot for the multiple options! Can you please check my comment on the sorting error above?

 

tex628
Community Champion
Community Champion

Hi, 

Create a calculated column in 'Table' that looks at the different values in [State]. 

Use something like this:

Column = 
SWITCH( [State];
"0-2" ; 0 ;
"3-5" ; 1 ; 
"6-12" ; 2 ; 

etc...

)


Then finally sort your [State] solumn using your new index column. Use the "Sort by column" functionality.

Br,
J

 


Connect on LinkedIn
Anonymous
Not applicable

Hi @tex628!

 

I've used the Switch function, but when trying to apply the sorting I got the error below. Can you advise?

 

Thanks.

 

Снимок экрана (76).png

 

tex628
Community Champion
Community Champion

My bad, PBI doesn't like it when you try to sort a column with another one that is dependant on the first. 

But the index column that we created isn't completly useless, if you drag it into the tooltip slot in the chart you can then directly sort the chart on that index column. 

If you don't want to have the index column in the tooltip you will need to recreate the table in power query instead, if you do you should not get the issue when you use "sort by column".

If you need any help with setting up the table in power query, just give me the word! 🙂

Br,
J

 


Connect on LinkedIn

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.

Top Solution Authors