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
shahiddcs
New Member

X Axix in line graph not order the classes

see the attached screenshoot

graph power bi.JPG

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @shahiddcs ,

 

Here are the steps you can follow:

If you don't have many [Class] types, try entering them manually:

1. Enter data – create a sort table.

vyangliumsft_0-1699948034618.png

2. In Power Query -- Add Column – Index Column – From 1.

vyangliumsft_1-1699948057383.png

vyangliumsft_2-1699948057385.png

3. Joining a relationship between two tables.

vyangliumsft_3-1699948078738.png

4. Select [Class] – Sort by – [Index].

vyangliumsft_4-1699948109219.png

vyangliumsft_5-1699948109233.png

If you have a large number of [Class] types that do not lend themselves to manual entry, you can use the following:

1. Create calculated table.

Table 2 =
var _table1=
DISTINCT('Table'[Class])
var _table2=
ADDCOLUMNS(
    _table1,"index",
    IF(
CONTAINSSTRING(
    [Class],"year")=TRUE(),
    VALUE(
    RIGHT(
        [Class],LEN([Class])-LEN("year "))),BLANK()))
return
ADDCOLUMNS(
    _table2,"rank",IF([index]=BLANK(),MAXX(_table2,[index])+1,[index]))

vyangliumsft_6-1699948163862.png

2. Joining a relationship between two tables.

vyangliumsft_7-1699948163864.png

3. Select [Class] – Sort by column – [rank].

vyangliumsft_8-1699948216107.png

4. Result:

vyangliumsft_9-1699948216114.png

 

 

Best Regards,

Liu Yang

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

4 REPLIES 4
Anonymous
Not applicable

Hi  @shahiddcs ,

 

Here are the steps you can follow:

If you don't have many [Class] types, try entering them manually:

1. Enter data – create a sort table.

vyangliumsft_0-1699948034618.png

2. In Power Query -- Add Column – Index Column – From 1.

vyangliumsft_1-1699948057383.png

vyangliumsft_2-1699948057385.png

3. Joining a relationship between two tables.

vyangliumsft_3-1699948078738.png

4. Select [Class] – Sort by – [Index].

vyangliumsft_4-1699948109219.png

vyangliumsft_5-1699948109233.png

If you have a large number of [Class] types that do not lend themselves to manual entry, you can use the following:

1. Create calculated table.

Table 2 =
var _table1=
DISTINCT('Table'[Class])
var _table2=
ADDCOLUMNS(
    _table1,"index",
    IF(
CONTAINSSTRING(
    [Class],"year")=TRUE(),
    VALUE(
    RIGHT(
        [Class],LEN([Class])-LEN("year "))),BLANK()))
return
ADDCOLUMNS(
    _table2,"rank",IF([index]=BLANK(),MAXX(_table2,[index])+1,[index]))

vyangliumsft_6-1699948163862.png

2. Joining a relationship between two tables.

vyangliumsft_7-1699948163864.png

3. Select [Class] – Sort by column – [rank].

vyangliumsft_8-1699948216107.png

4. Result:

vyangliumsft_9-1699948216114.png

 

 

Best Regards,

Liu Yang

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

Uzi2019
Super User
Super User

Hi @shahiddcs 
It is sorting based on Text order. If you see Overall, Year 10,Year 11 and so on.
If you want to sort it according to your need the you have to create Custom column then add that column into chart so it will then proper sorting values.

 

create calcualted column:
Sorting=

Sorting = SWITCH(TRUE(),
            Table[Year]="Overall", "1.Overall",
            Table[Year]="Year 7","2.Year 7",
            Table[Year]="Year 8","3.Year 8",
            Table[Year]="Year 9","4.Year 9",
             
Table[Year]="Year 10","5.Year 10",
            Table[Year]="Year 11","6.Year 11"
            )
you can manipulate above code as per your order. but this is way that your X axis will be sorting. We have added prefix as number (1. 2. 3.) so it will do the sorting according tothe numbers.

I hope I answered your question.
 
Don't forget to give thumbs up and accept this as a solution if it helped you!!!

my table is like below

Class              Year

Year 7       2020-2021

year 7       2021-2022

year 7      2022-2023

Year8       2020-2021

yera 8      2021-2022

year 8      2022-2023

yer 9       2020-2021

year 9     2021-2022

year 9      2022-2023

year10   2020-2021

year  10  2021-2022

year 10  2022-2023

year 11  2020-2021

year11  2021-2022

yer 11  2022-2023

overall  2020-2021

overall  2021-2022

overall   2022-2023

 

how to make new culumn as per your instruction

ITManuel
Responsive Resident
Responsive Resident

You will need to tell Power BI how your used columns should be ordered. Go to the Table view, select the column and click on "Sort by column". If you dont have an adequate column for sorting, you need to create one. 

 

Br

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!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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
Top Kudoed Authors