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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

sorting by month (text)

ssas tabular model - I have a month column, which is a text datatype, and is based on a day column which is date datatype

 

I have a power bi report doing live connection to this model, when I try to put the month column on x axis on a visual, it sorts according to a text, how to make it sort like a number ?

 

I tried doing =YEAR([xxx Day])&MONTH([xxx Day]), and keep the data format general and data type whole number, it stores data ase 20228 (instead of 202208)

 

the minute I change both data format and data type to whole number at the ssas cube, power bi sums it up , i cannot use summarization, how to solve this problem

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@Anonymous Your calculation should be:

=YEAR([xxx Day]) * 100 + MONTH([xxx Day])

 

Set this as your Sort By column of your text month name.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

@Greg_Deckler  why multiply by 100

@Anonymous It gives you the 0 for single digit months. 2022 * 100 = 202200 + your month number results in 202201, 202202, 202203, 202204, 202205, 202206, 202207, 202208, 202209, 202210, 202211, 202212 and thus this provides a consistent sorting by year and month.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

@Anonymous Your calculation should be:

=YEAR([xxx Day]) * 100 + MONTH([xxx Day])

 

Set this as your Sort By column of your text month name.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler  Why multiply * 100

@Anonymous See previous reply.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler  so I added a new column with above calculation in the msbi tabular model

 

year(day_column) * 100 + month

 

and data format General, data type whole number, the power pivot shows correct values but power bi sums it up and shows wrong values 

 

 

Hi @Anonymous 

 

This thread may be helpful: https://stackoverflow.com/questions/70458737/sort-a-calculated-column-ssas-tabular-model . After creating the new whole number data type column in the tabular model, select the original text data type Month column and set the Sort By Column property to the new whole number data type column. 

vjingzhang_0-1658815904095.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.