Aggregate Transformation in SSIS Advanced Mode

The Aggregate Transformation in SSIS supports multiple outputs. It means Aggregate Transformation can read the data from the source for once. And then, we can create various outputs, and each output may have a different set of aggregations. Here, we show you how to configure multiple outputs in aggregate transformation in SSIS advanced mode with example

TIP: Please refer to Aggregate Transformation article to understand the Aggregations and its functionalities.

Aggregate Transformation in SSIS Advanced Mode example

STEP 1: Open BIDS and Drag and drop the data flow task from the toolbox to control flow and rename it as Aggregate Transformation.

Aggregate Transformation in SSIS Advanced Mode 1

STEP 2: Drag and drop OLE DB Source, Aggregate Transformation from the toolbox to the SSIS data flow region

Aggregate Transformation in SSIS Advanced Mode 2

Double click on OLE DB source in the data flow region will open the connection manager settings and provides space to write our SQL statement. Here we are using DimGeography and [FactResellerSales] present in the AdventureworkDW2014

Aggregate Transformation in SSIS Advanced Mode 3

The SQL command we used in the above screenshot to retrieve data is:

SELECT [EnglishCountryRegionName]
      ,[StateProvinceName]
      ,[City]
      ,[PostalCode]
      ,RESELLER.[UnitPrice]
      ,RESELLER.[ProductStandardCost]
      ,RESELLER.[TotalProductCost]
      ,RESELLER.[SalesAmount]
      ,RESELLER.[TaxAmt]  
FROM [DimGeography]
  INNER JOIN 
     [FactResellerSales] AS RESELLER ON
 [DimGeography].[SalesTerritoryKey] = RESELLER.[SalesTerritoryKey]

STEP 4: Click on columns tab to verify the columns. In this tab we can uncheck the unwanted columns also.

OLE DB Source Editor to select Columns

STEP 5: Double-click on the Aggregate transformation to open the Aggregate Transformation editor. In the upper pane, we have a button to toggle between Basic and Advanced Mode. In this example, we want to configure multiple outputs, so select the Advance mode.

Once you click on the Advanced mode button, a new pane will be opened to configure multiple outputs.

  • Aggregate Name: Specify the aggregate name.
  • Group By Columns: Here, it shows the list of columns we used for grouping.

Next, in the lower pane, we select the required columns to perform Aggregate Transformation operations by checking them in Available Input Columns.

Once you check the required columns, then those column names will appear in the Input Column located in the lower pane, as shown in the below figure

Aggregate Transformation in SSIS Advanced Mode 5

From the above screenshot, you can observe that we were assigning Aggregation name as COUNTRY NAME and Group by as EnglishCountryRegionName.

Let us add one more aggregation and assigning name as STATE NAME and Group by as EnglishCountryRegionName, StateProvinceName.

Aggregate Transformation in SSIS Advanced Mode 6

From the above screenshot, we are calculating the Sum of Unit Price, Sum of Product Standard Cost, Average of Total Product Cost, Minimum of Sales Amount, and Maximum of Tax Amount. And Group by English Country Region then by State Province Name.

Let us add one more aggregation and assigning name as CITY and Group by as EnglishCountryRegionName, StateProvinceName, City.

Aggregate transformation in SSIS Advanced Mode 7

From the above, we are calculating the Sum of Unit Price, Average of Product Standard Cost, Minimum of Total Product Cost, Maximum of Sales Amount, and Sum of Tax Amount. And Group by English Country Region Then by State Province Name and Then by City.

STEP 6: Drag and drop 3 OLE DB destinations from the toolbox to the data flow region to configure the three output we get from Aggregate transformation.

Aggregate transformation in SSIS Advanced Mode 8

From the above, we renamed the OLEDB destinations to Group By Country, Group By State and Group By City

STEP 7: When you drag the Aggregate transformation output arrow to OLE DB destination an Input Output Selection window will open to select one of the output and here we are selecting COUNTRY NAME

Aggregate transformation in SSIS Advanced Mode 9

Let us assign State name output to second OLE DB destination

Aggregate transformation in SSIS Advanced Mode 10

We have one more output (CITY) left so, when we drag the green arrow from aggregate transformation to 3rd OLE DB Destination, it automatically assigns to City.

Aggregate transformation in SSIS Advanced Mode 11

STEP 8: Now, we have to configure the OLE DB destination for the country name. So double click on the OLE DB Destination and provide the required information.

Aggregate transformation in SSIS Advanced Mode 12

Here we are selecting the following database as destination database and [Group By Country] table as the destination table

STEP 9: Click on the Mappings tab to check whether the aggregate source columns exactly mapped to the destination columns.

Aggregate Mappings

STEP 10: Now, we have to configure the OLE DB destination for the group by state aggregation output. So double click on the OLE DB Destination and provide the required information

Aggregate transformation in SSIS Advanced Mode 14

Here we are selecting the following database as destination database and [Group By State] table as the destination table

Repeat Step 9

STEP 12: Now, we have to configure the OLE DB destination for the city output rows. So double click on the OLE DB Destination and provide the required information

Aggregate transformation in SSIS Advanced Mode 15

Here we are selecting the [Group By City] table as destination table

Repeat Step 9

Click ok to finish our package design. Let us run the package

Aggregate transformation in SSIS Advanced Mode 16

Let us see the result of Group By English Country Region Name. For this, open the Management studio and write the below query

SELECT [EnglishCountryRegionName]
      ,[UnitPrice]
      ,[ProductStandardCost]
      ,[TotalProductCost]
      ,[SalesAmount]
      ,[TaxAmt]
  FROM [GROUP BY COUNTRY]

OUTPUT

Aggregate Destination Table

Now, see the result of Group By English Country Region Name, State Province Name

SELECT [EnglishCountryRegionName]
      ,[StateProvinceName]
      ,[UnitPrice]
      ,[ProductStandardCost]
      ,[TotalProductCost]
      ,[SalesAmount]
      ,[TaxAmt]
  FROM [GROUP BY STATE]

OUTPUT

Aggregate Output

Let us see the result of Group By English Country Region Name, State Province Name and City

SELECT [EnglishCountryRegionName]
      ,[StateProvinceName]
      ,[City]
      ,[UnitPrice]
      ,[ProductStandardCost]
      ,[TotalProductCost]
      ,[SalesAmount]
      ,[TaxAmt]
  FROM [GROUP BY CITY]
Aggregate Destination Table