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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
v-jayw-msft
Community Support
Community Support

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.

 

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

7 REPLIES 7
v-jayw-msft
Community Support
Community Support

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.

 

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
Anonymous
Not applicable

Thanks @tex628, @v-jayw-msft!

 

v-jayw-msft
Community Support
Community Support

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.

 

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
Anonymous
Not applicable

Hi @v-jayw-msft,

 

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.