Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

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

 

  • 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:

     

    Then it will show like you want:

     

    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

16 Replies

  • v-deddai1-msft's avatar
    v-deddai1-msft
    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:

     

    Then it will show like you want:

     

    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's avatar
      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

  • Anonymous's avatar
    Anonymous
    Not applicable

    I had one question. If I have months like this
    Jan - 2024, feb 2024 etc 
    How can we sort this in descending order in column in matrix visual

    • Anonymous's avatar
      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.

       

      • sevenhills's avatar
        sevenhills
        Super User

        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]

         

         

        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.

         

         

         

        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

         

  • littlemojopuppy's avatar
    littlemojopuppy
    Community Champion

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

    • Anonymous's avatar
      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's avatar
        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.

         

        Thanks

         

  • v-deddai1-msft's avatar
    v-deddai1-msft
    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