Search code examples
sql-serverreporting-servicesssrs-2012

SSRS Sort matrix by column name


Let's say I have table with some rows and columns in sql. Columns are (id, column1,column2,column3), I did unpivot. And got dataset in ssrs like : Key,ColumnName,ColumnValue. I created matrix like below structure:

----------------------
Key     | ColumnName
----------------------
[Key]   | [ColumnValue]
------------------------

Question: How I can do something like: "Order by Column2" (or order by multiple column2,Column3) in matrix in SSRS? Where I need mention to sort by certain column name?


Solution

  • Maybe question was not clear enough. But with help of @Alan I found solution that works for me perfect. So if we want to get like "Order by Column1" then after unpivot Put your dataset in the matrixes. Go the the matrix which you want to Sort by specific column (in my case column1) Row group properties---->Sorting----> Add---> Expression:

    MAX( IIF(Fields!ColumnName.Value="Column1",Fields!ColumnValue.Value,Nothing) )

    and if you want to ad also Column2 to this matrix to sort, just after set 1st expression in the same window click --->add---> expression----> same query but with your column name (ex. Column2).

    Hope this will help to some one.