Answered by:
Pivot Table with Dynamic Columns and Headers

Question
-
Hello,
I'm trying to pivot a table of data where the column headers will be dynamic. While I know how to pivot the table to get what I want how will I be able to pick up the table column header from the Pivot to display in the report?
For example:
Unpivoted data is Employee Code, Branch Code, Problem Code, # of Problems.
There is many records for a given Employee and Branch that I want to pivot so the Column headers are the Problem Codes and the data below is the SUM(num_problems) for that Problem.
So the data may look like this for Tech Bob, Branch NY.
- Problem = LEAK, Num_problem = 5
- Problem = DAMAGE, Num_problem = 2
- Problem = OTHER, Num_problem = 3
Which problem codes may appear is unknown but selecting the DISTINCT(problem) across all techs gives me the column headings to use.
So if I pivot this data, I get this Row:
- Tech = Bob, Branch = NY, DAMAGE = 2, LEAK = 5, OTHER = 3
So first can SSRS handle having dynamic columns? Only Tech and Branch are known and the remaining columns are dynamic based on how many Problems they worked on.
Second, how can I set the column heading in my Tablix to be the Problem Code?
Sherry
Thursday, December 11, 2014 11:45 PM
Answers
-
You need to use the matrix style tablix. Here is a simple tutorial to get you started... http://technet.microsoft.com/en-us/library/cc627441%28v=sql.105%29.aspx
Jason Long
- Edited by Jason A Long Friday, December 12, 2014 12:22 AM
- Proposed as answer by Qiuyun YuMicrosoft contingent staff Friday, December 12, 2014 9:36 AM
- Marked as answer by Simon_HouMicrosoft contingent staff Thursday, December 18, 2014 5:36 AM
Friday, December 12, 2014 12:21 AM -
You just need to use a matrix container
Use EmployeeCode and BranchCode for row group
ProblemCode as column group and SUM([No Of Problems]) as the data expression and it will generate the columns for you based on ProblemCode values automatically.
See an example here
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
----------------------------
My MSDN Page
My Personal Blog
My Facebook Page- Proposed as answer by Qiuyun YuMicrosoft contingent staff Friday, December 12, 2014 9:36 AM
- Marked as answer by Simon_HouMicrosoft contingent staff Thursday, December 18, 2014 5:36 AM
Friday, December 12, 2014 1:45 AM
All replies
-
You need to use the matrix style tablix. Here is a simple tutorial to get you started... http://technet.microsoft.com/en-us/library/cc627441%28v=sql.105%29.aspx
Jason Long
- Edited by Jason A Long Friday, December 12, 2014 12:22 AM
- Proposed as answer by Qiuyun YuMicrosoft contingent staff Friday, December 12, 2014 9:36 AM
- Marked as answer by Simon_HouMicrosoft contingent staff Thursday, December 18, 2014 5:36 AM
Friday, December 12, 2014 12:21 AM -
You just need to use a matrix container
Use EmployeeCode and BranchCode for row group
ProblemCode as column group and SUM([No Of Problems]) as the data expression and it will generate the columns for you based on ProblemCode values automatically.
See an example here
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
----------------------------
My MSDN Page
My Personal Blog
My Facebook Page- Proposed as answer by Qiuyun YuMicrosoft contingent staff Friday, December 12, 2014 9:36 AM
- Marked as answer by Simon_HouMicrosoft contingent staff Thursday, December 18, 2014 5:36 AM
Friday, December 12, 2014 1:45 AM