Pivot Mapping in Informatica
Mapping technique to transpose rows into column data using aggregator
transformation.
Scenario-1
Often it is necessary to 'build' a target record from several source records.
One of the scenarios has been to pivot data in multiple rows belonging to the same entity. Multiple
rows may contain different attributes of the same entity. Then we need to build a process to map the
multiple attributes of the entity into multiple columns in a single row.
For example, source records:
CUSTOMER_ID, SEQUENCE_NUM, COMMENT
1,1,aaa
1,2,bbb
2,1,ccc
2,2,ddd
2,3,eee
3,1,fff
Would turn into target records:
CUSTOMER_ID, COUNT, COMMENT
1,2,aaabbb
2,3,cccdddeee
3,1,fff
There are a few different methods of building one record out of several. Often this can be
accomplished by using an aggregator. Alternatively, an Expression variable logic can be utilized. This
mapping template uses the aggregator transformation.
Scenario -2
This solution describes how to pivot data from the multiple rows into columns in a single row.
       Source
        CUSTOMER_ID         PRODUCT_CATEGORY          SALES_AMT
           CUST_1                CAT_A                   2000
           CUST_1                CAT_B                   3000
           CUST_1                CAT_C                   4000
           CUST_2                CAT_A                   8000
           CUST_2                CAT_C                   7000
       Target
       CUSTOMER_ID         CATEGORY_A_AMT          CATEGORY_B_AMT          CATEGORY_C_AMT
          CUST_1                2000                    3000                    4000
          CUST_2                8000                                            7000
There are a few different methods of building one record out of several. Often this can be
accomplished by using an aggregator. Alternatively, an Expression variable logic can be utilized. This
mapping template illustrates all the methods.
Scenario - 3
+---------+--------------+-----------------+
| ADDR_ID |     NAME     |     ADDRESS     |
+---------+--------------+-----------------+
|       1 | John Smith   | JohnsAddress1   |
|       1 | John Smith   | JohnsAddress2   |
|       1 | John Smith   | JohnsAddress3   |
|       2 | Adrian Smith | AdriansAddress1 |
|       2 | Adrian Smith | AdriansAddress2 |
|       3 | Ivar Smith   | IvarAddress1    |
+---------+--------------+-----------------+
And this should be the resulting table:
+---------+--------------+-----------------+-----------------+---------------+----------+
| ADDR_ID |     NAME     |    ADDRESS1     |    ADDRESS2     |   ADDRESS3    | ADDRESS4 |
+---------+--------------+-----------------+-----------------+---------------+----------+
|       1 | John Smith   | JohnsAddress1   | JohnsAddress2   | JohnsAddress3 | NULL     |
|       2 | Adrian Smith | AdriansAddress1 | AdriansAddress2 | NULL          | NULL     |
|       3 | Ivar Smith   | IvarAddress1    | NULL            | NULL          | NULL     |
+---------+--------------+-----------------+-----------------+---------------+----------+
Informatica Scenarios: Pivoting of records (Pivoting of Employees by Department)
In this scenario we will discuss about how to pivot a set of records based on column:
  Source Records:
      Dept_id         Emp_name
           10         CLARK
           10         KING
           10         MILLER
           20         JONES
           20         FORD
           20         ADAMS
           20         SMITH
           20         SCOTT
           30         WARD
           30         TURNER
           30         ALLEN
           30         BLAKE
           30         MARTIN
           30         JAMES
  Expected Output
      DEPT_ID         EMP_NAME
           10         CLARK|KING|MILLER
           20         JONES|FORD|ADAMS|SMITH|SCOTT
           30         WARD|TURNER|ALLEN|JAMES|BLAKE|MARTIN
For this we can use the below pivot_mapping. To get the required source records we have used the
below source query.
Select d.deptno,e.ename from emp e,dept d where e.deptno=d.deptno
Sort: Next step is to sort the Deptid using a Sorter or we can sort using the query directly.
In the expression we need to use the logic as shown below and arrange the columns in the below
order
V_EMP_NAME = DECODE(V_DEPT_PREV,DEPT_ID,V_DEPT||’|’||EMP_NAME, EMP_NAME)
O_EMP_NAME=V_EMP_NAME
V_DEPT_PREV=DEPT_ID
Group by dept_id: To group the deptid colum we can make use of the AGGREGATOR .
When we group by using the DEPTID it will group and return the last row of each department group
and the target table will have the below records as expected
SQL> SELECT * FROM PIVOT_TARGET;
DEPTN     ENAME
10   CLARK|KING|MILLER
20    JONES|FORD|ADAMS|SMITH|SCOTT
30    WARD|TURNER|ALLEN|JAMES|BLAKE|MARTIN
Pivot columns in a single row into multiple rows
Source
     AddressID        Name                 Address1         Address2
     1                Rachel Geller        address1         address2
     2                Joey Smith           address1         address2
Target
     AddressID        Name                 Address
     1                Rachel Geller        address1
     1                Rachel Geller        address2
     2                Joey Smith           address1
     2                Joey Smith           address2
In the above scenario, the column data is converted to rows. To normalize the data, we use normalizer
transformation. Go to Normalizer Transformation, to see, how to implement the above scenario.