Skip to content
Advertisement

Converting Multiple Rows to Columns

How would I convert rows into columns? In this case, taking the columns of Reason and Weight and expanding the values where more columns are created?

The column Reason will only have four values (whereas the field may be blank too): Natural, Emissions, and Humans.

Input Table Example:

Output Table Example

I was thinking of doing a pivot, but got a bit confused since I’m trying to deal with two columns that are dependent on others.

I tried to do a pivot, but I my above query in generating some horrible errors – at the same time, not sure if I’m missing a group by to ensure things are consolidating in the right way. Any guidance would be appreciated!

Advertisement

Answer

Perhaps this will help

Results

enter image description here

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement