Forum Discussion

JonHacking's avatar
JonHacking
Frequent Visitor
7 years ago

Sort by Columns On Unpivoted dataset

I have a table as below:

 

Consultant | Value A | Value B| Value C|....|Value Z|
Con 1         |           0 |           1|            3|...|           5|

I need a Table Visual Where you are able to add/remove Values Dynamically so have Unpivoted The 'Value' Columns To create the following dataset:

Consultant| Value Type|Value|
Con 1        | Value A     |       0|
Con 1        | Value B     |       1|
Con 1        |Value Z      |       5|

 

I've then built a matrix visual with Consultant as the row dimension, Value Type as the column dimension and Value as the Value dimension. I've then included Value Type as a Filter Visual so I can pick and Choose Columns.
However, this removes the ability to sort based on an individual column.

Is there any way to be able to choose columns dynamically whilst also being able to sort on individual columns?

Any help would be appreciated,

Thanks,

Jon

6 Replies

  • v-piga-msft's avatar
    v-piga-msft
    Icon for Resident Rockstar rankResident Rockstar

    Hi JonHacking ,

    I have a little confused about your requirement.

    Is there any way to be able to choose columns dynamically whilst also being able to sort on individual columns?

    What is the individual columns do your mean? Do you want to sort by column headers in matrix like below.

    Actually, we cannot sort by column field in matrix directly in Power BI and the column is ordered by A-Z by default in matrix.

    If you want to sort your columns in matrix, you could use Sort by Column under modeling tab in Power BI.

    I made a sample which should be more obvious.

    Assuming that you have the data like below and you want to create the matrix the unpivot data, then sort the column by month.

    You need to add an index column after unpivot columns.

    Then you need to sort month column by index column.

    Here is the output.

    Hope this can help you.

    Best Regards,

    Cherry

     

    • JonHacking's avatar
      JonHacking
      Frequent Visitor

      Hi v-piga-msft ,

       

      Apologies, I realize what I said before was a bit vague and am unsure how to upload images without an image hosting service. So will try my best to clarify below:

       

      I have the report set up as per your first image, albeit with more than 1 constant (e.g. Con 1, Con 2, Con 3 etc.)

       

      What I want to be able to do is keep the Attribute filter, whilst being able to sort by the SUM of one of the matrix columns.

       

      e.g. From This:

       

      Constant  | Value A   |  Value B  |  Value C  |
      Con 1       |           3   |             0 |              0 |
      Con 2       |           5   |             1 |              0 |
      Con 3       |           4   |             2 |              1 |

      To This:

       

      Constant  | Value A ↓|  Value B  |  Value C  |
      Con 2       |           5   |             1 |              0 |
      Con 3       |           4   |             2 |              1 |
      Con 1       |           3   |             0 |              0 |

       

      Hopefully this makes sense,

      Jon

      • v-piga-msft's avatar
        v-piga-msft
        Icon for Resident Rockstar rankResident Rockstar

        Hi JonHacking ,

        By my tests, we cannot achieve your desired output directly in matrix, but we could create a measure to achieve that.

        Measure = CALCULATE(MAX('Table2'[Value]))

        Then you could drag the measure under Value Field to create the matrix like below and sort by measure. 

        More details, please refer to my attachment.

        Best Regards,

        Cherry