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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Month Sorting in a Matrix

Hello,

 

I have a set of data I want to view comparing results on a month-to-month basis for the last three months.

 

The rows are the various metrics, the columns are the month of the week-ending date (a datetime type), and there are three values for the middle of the matrix. I basically dropped the field into the column, had the hierarchy displayed, and deleted everything but the month portion. 

 

The results work fine when not crossing a year boundary, however as we now have values for January, columns arrange as January, October, November, December. I understand that it 'makes sense' given that I'm pulling the month field only and January is month 1. However, including the year portion creates another grouping that really isn't needed. 

 

I did go into the data and set the "sort by column" value without a result.

 

Any suggestions are appreciated; we don't need the year displayed as the visual implies the year as it is a three-month look-back.

 

Thanks

 

1 ACCEPTED SOLUTION
v-deddai1-msft
Community Support
Community Support

Hi @Anonymous ,

 

If you don't have duplicated month value in your fact table, you can try the following steps:

 

1. Create the calendar table:

Calendar = ADDCOLUMNS(CALENDAR(DATE(2020,10,1),DATE(2021,1,31)),"Year",YEAR([Date]),"MonthNum",MONTH([Date]),"Month",FORMAT([Date],"mmm"),"YEARMONTH",YEAR([Date])*100+MONTH([Date]))

 

2. Sort the month column by YEARMONTH column:

2.PNG

 

Then it will show like you want:

Capture.PNG

 

But if you have duplicated month value in your fact table, you really need to put year in the column.

 

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

 

Best Regards,

Dedmon Dai

View solution in original post

15 REPLIES 15
v-deddai1-msft
Community Support
Community Support

Hi @Anonymous ,

 

Would you please refer to the pbix file: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EQMGgP4_WNBKlWouIb2JhpkBa6cEPFVUuiCpSId6x9ZTFQ?e=Oun1UX?

 

And if you have an 18-month look back , for example,2019.6 -2020.12, there are duplicated month value for jan, feb and so on. sort by column will result in error. And we need to use year column to distinguish them.

 

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

 

Best Regards,

Dedmon Dai

v-deddai1-msft
Community Support
Community Support

Hi @Anonymous ,

 

If you don't have duplicated month value in your fact table, you can try the following steps:

 

1. Create the calendar table:

Calendar = ADDCOLUMNS(CALENDAR(DATE(2020,10,1),DATE(2021,1,31)),"Year",YEAR([Date]),"MonthNum",MONTH([Date]),"Month",FORMAT([Date],"mmm"),"YEARMONTH",YEAR([Date])*100+MONTH([Date]))

 

2. Sort the month column by YEARMONTH column:

2.PNG

 

Then it will show like you want:

Capture.PNG

 

But if you have duplicated month value in your fact table, you really need to put year in the column.

 

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

 

Best Regards,

Dedmon Dai

Anonymous
Not applicable

I must have missed something in your explanation as you are using the data I sent up. I followed, I thought, the instructions you provided and am still getting the results in a non-month order. 

1. Created the new calendar table

2. Sorted it by the yearmonth column

3. Created a relationship from the new calendar table to the data table

4. Added a new visual

5. Put the category in the row section, the month from the new calendar table into the column field, and tickets (Count) into the values. 

It resulted in the order of Dec, Jan, Nov for the data. Can you post the PBIX so I can see what I didn't do correctly?

Also, "But if you have duplicated month value in your fact table, you really need to put "year" in the column." do you mean that if I did this as an 18-month look back that the year would need to be included in the columns field?

 

Thanks

littlemojopuppy
Community Champion
Community Champion

Can you provide some sample data, a screen shot and the DAX for the measures you're trying?

Anonymous
Not applicable

Hello,

 

I am not using any dax for values, here is some sample data:

 

 

Tickets
(text)
Category
(text)
Task_Closed_End_Of_Week_dt
(datetime)
3861AD Object Deletion2020-12-26T23:59:59.9999999
2328Manual Account Modification2020-12-26T23:59:59.9999999
3158Manual Account Modification2020-12-26T23:59:59.9999999
0275Manual Account Modification2021-01-02T23:59:59.9999999
2648Manual Account Modification2020-12-26T23:59:59.9999999
2970Manual Account Modification2020-11-26T23:59:59.9999999
2864Manual Account Modification2020-11-26T23:59:59.9999999
2667Manual Account Modification2021-01-02T23:59:59.9999999
0161Manual Account Modification2020-12-26T23:59:59.9999999
3472Manual Account Modification2020-12-26T23:59:59.9999999
3048Manual Account Modification2020-12-26T23:59:59.9999999
5674Service Account2020-12-26T23:59:59.9999999
8226Storage2021-01-02T23:59:59.9999999
8233Storage2021-01-02T23:59:59.9999999
8220Storage2021-01-02T23:59:59.9999999
6122Storage2020-12-26T23:59:59.9999999
9452Update Group Scope2020-12-26T23:59:59.9999999
4371Update Group Scope2021-01-02T23:59:59.9999999
9237Update Group Scope2020-12-26T23:59:59.9999999
4401Update Group Scope2021-01-02T23:59:59.9999999
5181Update Group Scope2021-01-02T23:59:59.9999999
8046Update Group Scope2020-11-26T23:59:59.9999999
9129Update Group Scope2020-11-26T23:59:59.9999999
5626Update Group Scope2020-12-26T23:59:59.9999999
Anonymous
Not applicable

Had to do this as 2 different posts, I didn't understand why it kept failing. Anyway, here is a screenshot. As you can see, the month of January goes in front of November unless I also include the year in the column. It may be "as designed" and that's fine as an answer, but I'm hoping to not have to clutter up a visual with a year. I don't need the space for the row as well as I need the entire total not broken down by 'year' as shown in the second visual.

The column value is just pulling the month out of the date hierarchy.

 

TMOCostanzo_0-1609791303383.png

Thanks

 

Hi @Anonymous ...you're not trying to calculate month on month comparison (which is what I originally interpreted your request as).  You're literally just trying to get January 2021 to appear after December 2020, right?  You basically want this is your output, right???

littlemojopuppy_0-1609798005760.png

 

Do you have a date table and is it marked appropriately?  If not, create one.  Easiest way is to use the CALENDARAUTO function.  You can add columns for year, quarter, month, etc.  Check the "Date and Time Functions" listed here.  If you want to create MonthName or WeekdayName fields the easiest way is like this: FORMAT(Calendar[Date], "MMMM") for month name and substitute "DDDD" for weekday.  Once you add those, if you created MonthName and WeekdayName fields, you should sort them by the appropriate number fields you created.  But your goal is to have a date table that looks like this.

littlemojopuppy_1-1609798553837.png

 

After you do that, you can either create a hierarchy in the date table for year/month or just drop year, month, etc.  into the field well for the visualizations (year first, then month, etc).  Your visualization should end up like the first pic.

Anonymous
Not applicable

Thanks.

 

I don't want to drop the year into the visualization as it takes up valuable canvas and is inferred by it being the last three months.

 

Also, it just seems....overkill... to have to create a calendar table to do this simple thing. A calendar table generates all dates based upon the minimum/maximum of the date fields in the model, so I'm generating 3 years of dates for a simple ask. Seems crazy.

 

With this video from Guy In a Cube https://www.youtube.com/watch?v=2f7dYB1l84g he shows how to do month-to-month comparisons as well without needing to create that overhead in the model. *shrug*

 

I've done my best to replicate your suggestion - however, it does not seem to order by the month (Nov, Dec, Jan) without me including the year in the column. Maybe I'm missing something obvious from your suggestion, so I've included a link to my PBIX on my google drive.

Simple PBIX with Data 

 

Thanks

sevenhills
Super User
Super User
Anonymous
Not applicable

I don't know what you are attempting to show here. I'm not having an issue with sorting by the month name unless it's your assertion that I create a measure that combines the 4 digit year preceding the month name.

 

Hi  @Anonymous 

 

Sorry, since you are already advanced user (than me), based on the profile, I did not go in details. 

 

I had similar requirement in the past and want to present the data for matrix. so I did like below steps. (for some reasons, my profile do not allow me to upload pbix file)

 

[I edited this original post reply]

 

sevenhills_3-1609876409612.png

 

Columns

  • MM = Month('Calendar'[Date])
  • YYYYMM = Format('Calendar'[Date], "YYYYMM")
  • Month = Format('Calendar'[Date], "mmmm")
  • Month - 2 = 'Calendar'[Date]
  • YYYYMMDD = format('Calendar'[Date], "YYYYMMDD")

 

Format the "Month - 2" as mmmm and sort the column using YYYYMM

 

Note: It only works for matrix, which was my requirement too.

 

sevenhills_2-1609876363262.png

 

 

The image shows all data, but typically we do rolling 12 months or (12+1) 13 months in matrix. 

 

hint: I created as many format types to the needs in date/calendar table and use it. 🙂 

 

Hope this helps!

 

Thanks

 

Anonymous
Not applicable

Thanks - yeah, I have done some advanced things in the past, but I still have gaps in my knowledge you can drive a semi-truck through. I appreciate the more detailed answer so I could see your thought process and how it applied to the post you linked.

 

I tried that and didn't have any luck, I think it's because I'm using a matrix visualization as opposed to a table or other visual - they seem to react differently.

 

give me two minutes, my explanation looks wrong ... will update by looking my pbix file

Hi @Anonymous ,  I updated my original reply above, please check

Hi @Anonymous 

 

I download your PBIX file.

 

a) Modified your calendar table as

Calendar = ADDCOLUMNS ( CALENDARAUTO (),
    "Year", FORMAT([Date], "yyyy"), 
    "MonthNo", MONTH([Date]), 
    "Month", FORMAT([Date],"MMM"),
    "Quarter", FORMAT([Date],"\QQ"),
    "YearMonth", FORMAT([Date],"YYYY-MM"), 
    "WeekdayNo", WEEKDAY([Date],2), //1-Sun..Sat, 2-Mon..Sat
    "Weekday", FORMAT([Date],"ddd"), 
    "WeekNo", WEEKNUM([Date], 2),
    "Month - 2", [Date]
 )

b) Select "Month - 2" and clicked Sort by Column as "YearMonth"

sevenhills_0-1610057936978.png

 

c) matrix modified to use "Month -2" and it works!

sevenhills_1-1610057981760.png

 

Thanks

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.