06-29-2016 01:11 PM
I have a SQL database that I have connected to. It has over 8 million rows of customer data. The data runs from 2004-2015.
I have broken the data up into years and then sorted them by month.
I then used our utility's unique identifier in a query to only provide the unique numbers.
What I want to do is use the unique ID as the first column and a column for Jan 2004 and if will take all of the data for each customer and place it in that column if the date is Jan 2004 and so on for each year.
Here is what the data currently looks like:
ID, CAL MONTH, DEMAND
a 1 6
b 12 6
f 1 4
d 2 3
e 6 2
f 2 7
So the customers have 12 months worth of data and I need the demand data for each month as a new column.
Here is what I would like it to look like:
ID, JAN 2004, FEB 2004
a 6 6
b 6 7
c 6 8
d 7 10
e 9 12
f 6 6
Any help is greatly appreciated!
06-29-2016 02:11 PM
First, if you have more than one record per customer / month, use the Summary Statistics task and summarize by customer and month, to get a total. Don't print the output, get an output dataset instead.
Once you have this, or starting with this if it's what you've got, you should have a dataset that looks like:
|. . .|
|. . .|
Then you can use the Data | Transpose... task to create your output. Select ID as a Group variable, Demand as the Transpose variable, and Month as the "New Column Name" variable.