Forum Discussion

P_D_G's avatar
P_D_G
Resolver III
5 years ago
Solved

Pivot table based on multiple values / rows to columns

Hi all,

 

I have the below dataset and I'd like to have it in a new format (2nd table).

 

I've already created this in Power Query by pivoting the table in 2 separate queries:

1) pivot based on Value_A

2) pivot based on Value_B

then

3) add a new column (e.g.: Type: which has value A in the first and B in the second table)

and finally

4) append the 2 queries into 1 new.

 

My issue is that it seems to be a bit time consuming especially when I have A,B,C,D,E... values too, do you have any idea how to replicate this in a more efficient way? I don't want to summarize the values or execute any type of modification.

Input:

CountryYearValue_AValue_B
Country_1202048
Country_1202100
Country_12022510
Country_2202093
Country_2202138
Country_2202234
Country_3202037
Country_3202128
Country_3202252

 

Result:

YearCountry_1Country_2Country_3Type
2020493A
2021032A
2022535A
2020837B
2021088B
20221042B

 

 

Thanks,

PDG

 

 

 

4 Replies