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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Month year sorting in direct query

I have a month year column from Jan 2018 - July 2019. 

Month Year

Jan 2018

Feb 2018

Mar 2018

.

.

Jul 2019.

 

Usually when i want to sort this in the same order as above in an import query, I just create a custom column : Table[Year]*100 + [Month Number] and then sort month year with this column.

 

However, not sure why maybe because now it is a DIRECT QUERY, i am not able to use the above logic to sort it. IT just throws an error. Any idea how to sort it now? Thanks!

5 REPLIES 5
v-lili6-msft
Community Support
Community Support

hi, @Anonymous 

Here is a similar thread for your reference:

Sorting a text column using Direct Query

 

Best Regards,

Lin

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

@v-lili6-msft  Hey  thought about that but I cannot hard code the value through switch statement as it is a month year column. if i say when jan 2018 , then 1 and so on.. every month there is a new month year and i would have to keep adding it to my switch statement.

HI, @Anonymous 

You could use Contains in the formula to get Month No column, and then use Split to get Year column.

Then you could get Year month by the same logic in Edit Queries.

6.JPG

 

Best Regards,

Lin

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

@v-lili6-msft  But in this case would it not give all jan's = 1. Then my axis would be:

 

jan 2018 jan 2019 ..  feb 2018 feb 2019....... 

But i would like it to be .. jan 2018 feb 2018 ..... jan 2019 feb 2019

parry2k
Super User
Super User

@Anonymous unfotunately you cannot do this, here it says about modelling limitatons (also listed below)

 

Modeling limitations

The term modeling in this context means the act of refining and enriching the raw data, as part of authoring a report using it. Examples include:

  • Defining relationships between tables
  • Adding new calculations (calculated columns and measures)
  • Renaming and hiding columns and measures
  • Defining hierarchies
  • Defining the formatting, default summarization and sort order for a column
  • Grouping or clustering values


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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