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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
gbarr12345
Post Partisan
Post Partisan

Month and Year field not in order

Hi,

 

I created a calculated column to combine the month and year as below:

 

gbarr12345_0-1721614701485.png

 

However, when I pull it in to a graph, I want it to be in order. For example, like January 2024, February 2024, March 2024 etc.

 

It is instead putting all the January's together and so on:

 

gbarr12345_1-1721614768972.png

 

 

Is there an easy way to fix this?

 

Many Thanks in advance.

1 ACCEPTED SOLUTION
Ritaf1983
Super User
Super User

Hi @gbarr12345 
Since month year is a text data type, the engine cannot sort it chronologically, because it is just a string.

So you should add a numeric column that will hold the sorting logic.

This column can be a combination of year and month, you can add it from power query to your calendar table :

Ritaf1983_0-1721615464925.png

and then from the data view sort your column :

Ritaf1983_1-1721615568046.png

More information about working with calendar tables include a full script for creating it here :

https://radacad.com/create-a-date-dimension-in-power-bi-in-4-steps-step-1-calendar-columns

Information about sorting by another column :

https://learn.microsoft.com/en-us/power-bi/create-reports/desktop-sort-by-column?tabs=powerbi-deskto...

PBIX with my example is attached

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

12 REPLIES 12
Jihwan_Kim
Super User
Super User

Hi,

One of many ways is, I suggest creating one more calculated column, and that is Month Year sort Calculated Column. After creating it, configure Month Year column to be sorted by Month Year sort column.

 

Please check the below picture and the attached pbix file.

 

 

 

Month Year sort CC = 
EOMONTH('calendar'[date],0)

 

 

EOMONTH function (DAX) - DAX | Microsoft Learn

 

 

Jihwan_Kim_0-1721616303468.png

 

Jihwan_Kim_1-1721616345299.png

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Hi Jihwan,

 

Thank you for your reply.

 

I tried all your steps, however it's still not in the order I'm looking for. See screenshots below:

 

gbarr12345_0-1721618126479.png

 

 

gbarr12345_1-1721618134590.png

 

gbarr12345_2-1721618145380.png

 

gbarr12345_3-1721618155342.png

 

 

gbarr12345_4-1721618162027.png

 

 

gbarr12345_5-1721618177620.png

 

 

 

Ritaf1983
Super User
Super User

Hi @gbarr12345 
Since month year is a text data type, the engine cannot sort it chronologically, because it is just a string.

So you should add a numeric column that will hold the sorting logic.

This column can be a combination of year and month, you can add it from power query to your calendar table :

Ritaf1983_0-1721615464925.png

and then from the data view sort your column :

Ritaf1983_1-1721615568046.png

More information about working with calendar tables include a full script for creating it here :

https://radacad.com/create-a-date-dimension-in-power-bi-in-4-steps-step-1-calendar-columns

Information about sorting by another column :

https://learn.microsoft.com/en-us/power-bi/create-reports/desktop-sort-by-column?tabs=powerbi-deskto...

PBIX with my example is attached

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Hi Rita,

 

Thank you for your response.

 

I can't seem to see the option to create a custom column.

 

Is it because we may have different versions of power bi or something?

 

gbarr12345_0-1721616072424.png

 

No, this is because you are not in POWER QUERY.

Ritaf1983_0-1721616257823.png

 

Ritaf1983_1-1721616314578.png

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

 

 

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Thanks for the help Rita!

Happy to help 🙂

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Hi Rita,

 

I tried creating the custom column there and it seems to be throwing out an error as below.

 

Any idea what's wrong with it?

 

gbarr12345_0-1721681187983.png

 

I actually I fixed the above, it was just a syntax error.

 

However, I'm now getting this error on the last step you showed through the pictures above:

 

gbarr12345_0-1721683308778.png

 

 

 

gbarr12345_1-1721683349218.png

 

 

gbarr12345_2-1721683400505.png

 

 

Hi @gbarr12345 

This error message indicates an inconsistency in your Month and Year columns that conflicts with the sorting criteria.

Explanation:

The error message arises when the sorting operation encounters duplicate values in the column being sorted (Month and Year) while attempting to sort by another column (presumably, a column containing unique values). This inconsistency prevents Power BI from determining the correct order for the elements.

Troubleshooting Steps:

 

1. Check for Empty Cells: Ensure that there are no empty cells in the Month and Year columns. Empty cells can be interpreted as different values, leading to sorting inconsistencies.

2. Verify that you use a calendar table like in the pbix, attached in my first response.

3. Data Type Validation: Validate that the data type of the sort column is set to "Wole Number" and not "Text". Treating these columns as text can lead to misinterpretations during sorting.

Ritaf1983_0-1721703200673.png

 


For more assistance, I need to see your pbix.

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Thanks for the explanation Rita, I'll follow those steps!

 

Many Thanks for your help!

 

Apologies, I found it. Ignore the above thanks!

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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

Top Solution Authors