I have a table like this :
Month_ID Month_Sales
1 500.0
2 250.0
3 150.5
I want to add a new column to this table which is "Growth" where :
Growth = (Current Month Sales - Prev Month Sales) / Prev Month Sales
I want to do this using SSIS script component. How can I do this?
1/Create 2 package variables:
CurrentMonthSales
PrevMonthSales
Both are Double
2/ Use a Data Flow Task where you need a source component (depends on the data source you are dealing with) and select if it is a table or a query.
Let's consider it a table.
3/Drag
Row Countin the Data Flow Transformations list. Double click it and in the Section Variable Names, select the variableUser::CurrentMonthSales. Row Count task will save, in runtime, the result of the calculation in that variable.4/Use a second Data Flow Task in the Control Flow. Inside drag another OLEDB Source with the same table . Use another Row Count Task, but this time use the variable
User::PrevMonthSales. After the Row Count Task use either a Script Component or a derived column.5/If you use Derived Column, write a name for the column, choose the option 'Replace the name of your column' if you want to replace the value of your column, or 'Add column' if you want to add that as a column output.
6/In the expression, apply the formula:
and map to the corresponding column in your destination component.