Forum Discussion

JustinDoh1's avatar
JustinDoh1
Post Prodigy
5 years ago
Solved

Reorder columns for Matrix visualization (with sort order data provided from the same table)

I am trying to reorder the column order for a Matrix visualization.

So, I am trying to have "Medicare A" (ReportColumnOrder = 1) as displayed far left, then after "Medicate HMO"

(ReportColumnOrder = 2) would be next left to "Medicare A" etc.

 

Bottom is screenshot.

 

I already prepared a dataset that has the data of sort order ("1,2,3..9") matching with "PayerNameRedefined" column shown below:

 

I searched online, and I found a solution that is adding a query (using M language), but this case is not using column name.

I also found another solution somewhat similar, but this one is not with Matrix visualization and sorting works in visualization part when sorting was performed at Data view level. 

 

Given that I have a data that already provides the order (1...9), would it be a somewhat simple approach?

BTW, this particular column ("ReportColumnOrder") that has the sort order is not displayed on the Matrix visualization.

 

Is it possible to somehow insert this column ("ReportColumnOrder") as hidden and sort the column that way? 

 

I am guessing I would probably need to write a M language inside Power Query.

 

(I am trying to make this sort order as dynamic as possible for all other similar reports without having to insert extra code in Power BI).

 

Thanks for help!  

 

 

 

 

 

 

  • Hi JustinDoh1 ,

    Select the [PayerNameDefined] column, use 'Sort by column' feature in Columns tools and sort the column by the [ReportColumnOrder] column, you will get the result.

     

    Best Regards,
    Community Support Team _ Yingjie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • v-yingjl Thank you. I was thinking in a harder way. When I searched thru Google, there were so many other solutions related to similar cases, so I thought I have to solve in Power Query (M language).  Also, there was some error on SQL side, so I had to fix it.

9 Replies

    • Apetit's avatar
      Apetit
      New Member

      Solution doesn't apply to a Matrix

      • JayBabcock's avatar
        JayBabcock
        Frequent Visitor

        Same problem here - I can use method when sorting tables, but once it's in a matrix I cannot sort the columns... they seem to only want to sort alphabetically, so my only way around that was to manipulate the Column names... big inconvenience

  • v-yingjl's avatar
    v-yingjl
    Community Support

    Hi JustinDoh1 ,

    Select the [PayerNameDefined] column, use 'Sort by column' feature in Columns tools and sort the column by the [ReportColumnOrder] column, you will get the result.

     

    Best Regards,
    Community Support Team _ Yingjie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • JustinDoh1's avatar
      JustinDoh1
      Post Prodigy

      v-yingjl Thank you. I was thinking in a harder way. When I searched thru Google, there were so many other solutions related to similar cases, so I thought I have to solve in Power Query (M language).  Also, there was some error on SQL side, so I had to fix it.

    • thentangler's avatar
      thentangler
      Frequent Visitor

      I tried this, but the columns are still not sorting horizontally. 

    • SteffanieJ's avatar
      SteffanieJ
      Frequent Visitor

      Hello - I tried this and received the following error message. To get the order# in a new column I used a SWITCH formula.  How can I fix this?

       

       

       

  • HappyFabric's avatar
    HappyFabric
    Microsoft Employee

    For Matrix I could only get it to work if I created a new column in my data table. I could not create a Measure to define the new sorting column.