Forum Discussion
Complex ADF transformation on Specific Rows to Columns
Hello Experts,
I have a transformation that I have tried a few dataflow scenarios that do not yield the results needed. We have a file that extracts data like the below sample:
COL1 | COL2 |
Manufacturing | |
1-Jan-23 | |
Baked Goods | |
Lemon Cookies | |
Raw Materials | 40470 |
Factory Overheads | 60705 |
Staff Costs | 91057.5 |
Electricity | 136586.25 |
I would like the output table to look like the below:
COL1 | COL2 | NewCOL3 | NewCOL4 | NewCOL5 | NewCOL6 |
Raw Materials | 40470 | Manufacturing | 1-Jan-23 | Baked Goods | Lemon Cookies |
Factory Overheads | 60705 | Manufacturing | 2-Jan-23 | Baked Goods | Lemon Cookies |
Staff Costs | 91057.5 | Manufacturing | 3-Jan-23 | Baked Goods | Lemon Cookies |
Electricity | 136586.25 | Manufacturing | 4-Jan-23 | Baked Goods | Lemon Cookies |
The transformation should take the values of the first 4 rows as new column values and remove any nulls or whitespaces. I have used UNPIVOT and LOOKUP transformations but they return the column name as the value and not the values in rows 1-4, so I know I am missing a step in the process. Any suggestions on the dataflow for this challenge?
GemmaLowe I am guess you missed removing all the nulls or blanks from the columns during the transformation process.
You can configure the Flatten transformation to include only non-empty values from COL1 and COL2.
This will prevent unnecessary values in the flattened result.After flattening, add a Derived Column transformation and create new columns (NewCOL3, NewCOL4, NewCOL5, NewCOL6) referencing the flattened values from the original COL1 and COL2 columns.
You can use expressions like:
NewCOL3 = iif(FlattenedValues != '', COL1, '') NewCOL4 = iif(FlattenedValues != '', COL2, '') NewCOL5 = iif(FlattenedValues != '', LEAD(FlattenedValues, 1), '') NewCOL6 = iif(FlattenedValues != '', LEAD(FlattenedValues, 2), '')
In your approach, you attempted to use the LOOKUP transformation, which is a valid step. However, instead of using the column names as values, you should reference the actual values from the first 4 rows (Manufacturing, 1-Jan-23, Baked Goods, Lemon Cookies) to create the new columns (NewCOL3, NewCOL4, NewCOL5, NewCOL6).
You can read more at Microsoft Learn
Let me know if this works for you. @ me in replies, or I'll lose your thread!!!
Note:If this post is helpful, please mark it as the solution to help others find it easily. Also, if my answers contribute to a solution, show your appreciation by giving it a thumbs up!
- BabatundeDallasBrass Contributor
GemmaLowe I am guess you missed removing all the nulls or blanks from the columns during the transformation process.
You can configure the Flatten transformation to include only non-empty values from COL1 and COL2.
This will prevent unnecessary values in the flattened result.After flattening, add a Derived Column transformation and create new columns (NewCOL3, NewCOL4, NewCOL5, NewCOL6) referencing the flattened values from the original COL1 and COL2 columns.
You can use expressions like:
NewCOL3 = iif(FlattenedValues != '', COL1, '') NewCOL4 = iif(FlattenedValues != '', COL2, '') NewCOL5 = iif(FlattenedValues != '', LEAD(FlattenedValues, 1), '') NewCOL6 = iif(FlattenedValues != '', LEAD(FlattenedValues, 2), '')
In your approach, you attempted to use the LOOKUP transformation, which is a valid step. However, instead of using the column names as values, you should reference the actual values from the first 4 rows (Manufacturing, 1-Jan-23, Baked Goods, Lemon Cookies) to create the new columns (NewCOL3, NewCOL4, NewCOL5, NewCOL6).
You can read more at Microsoft Learn
Let me know if this works for you. @ me in replies, or I'll lose your thread!!!
Note:If this post is helpful, please mark it as the solution to help others find it easily. Also, if my answers contribute to a solution, show your appreciation by giving it a thumbs up!