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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Sort chart months up until current date

Hi,

 

I want to show some data which has sales amount from the previous 12 months on a column chart. When I add all my data to the chart it automatically sorts the columns from January-December even though September-Decembers data is from the year previous.

 

below is how the data is set out.

 

1.png2.png

Thanks,

 

1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey,

 

you have to use a column for the x-axis that also contains the year.

 

You can create a Calculated Column using the DAX statement: 

 

Year-Month = FORMAT('<tablename>'[MonthDate] , "YYYY-MM")

This will create something like this "2018-09" and will represent September 2018. You might want to create two columns one containning the year and one containing the month name (please be aware that the month name has to be sorted by a month number: https://docs.microsoft.com/en-us/power-bi/desktop-sort-by-column#sort-using-the-sort-by-column-butto...)

To create a chart like this:


image.png

 

it's necessary to create two additional columns that contain the year and the month. To create a calculated column that contains the monthname, you can use this DAX statement:

Month Name = FORMAT('<tablename>'[Monthdate] , "MMM")

Make sure that this column is sorted by an extra column that just contain the month number, you can create this calculated column by using this DAX:

Month Number = MONTH('<tablename>'[MonthDate])

After creating all the columns it's necessary to arrange the year and month name column for the visual like so:

image.png

 

Make both colummns are expanded:

image.png

Disable the property "Concatenate labels" from the X Axis band of the visual:

image.png

 

Make sure the X Axis is sorted accordingly:

image.png

 

You may also have to change the sort order to "Ascending".

 

Hopefully this provides you with some ideas.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

2 REPLIES 2
TomMartens
Super User
Super User

Hey,

 

you have to use a column for the x-axis that also contains the year.

 

You can create a Calculated Column using the DAX statement: 

 

Year-Month = FORMAT('<tablename>'[MonthDate] , "YYYY-MM")

This will create something like this "2018-09" and will represent September 2018. You might want to create two columns one containning the year and one containing the month name (please be aware that the month name has to be sorted by a month number: https://docs.microsoft.com/en-us/power-bi/desktop-sort-by-column#sort-using-the-sort-by-column-butto...)

To create a chart like this:


image.png

 

it's necessary to create two additional columns that contain the year and the month. To create a calculated column that contains the monthname, you can use this DAX statement:

Month Name = FORMAT('<tablename>'[Monthdate] , "MMM")

Make sure that this column is sorted by an extra column that just contain the month number, you can create this calculated column by using this DAX:

Month Number = MONTH('<tablename>'[MonthDate])

After creating all the columns it's necessary to arrange the year and month name column for the visual like so:

image.png

 

Make both colummns are expanded:

image.png

Disable the property "Concatenate labels" from the X Axis band of the visual:

image.png

 

Make sure the X Axis is sorted accordingly:

image.png

 

You may also have to change the sort order to "Ascending".

 

Hopefully this provides you with some ideas.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Anonymous
Not applicable

That's perfect! Thank you ever so much.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.