Forum Discussion

Funk-E-Guy's avatar
Funk-E-Guy
Helper II
1 year ago
Solved

Power Query - Unpivot multiple value groups into multiple value columns?

I have a department that really like to forecast in a tabular format, but they split monthly quantities into two groups of columns:       Organic Promotion Country Item Jan Feb Mar Ap...
  • Funk-E-Guy's avatar
    1 year ago

    Thank you both, Ashish_Mathur and lbendlin. For confidentiality I kept my data vague, but your comments pointed me in the right direction.

     

    To help others, here's the generalized explanation of what I did:

     

    1. Instead of having "Super Headers" for "Organic" and "Promo", I changed the table so that the monthly headers said "Jan Organic", ... , "Dec Promo"
    2. I unpivoted all 24 columns together. This gave me 24 rows for each entry (it'll be 12 by the end).
    3. A new "Attribute" column appears that contains "Jan Organic", ... , "Dec Promo"
    4. I add a new column "Month" that pulls text before delimiter " " (a single space). This isolates "Jan" thru "Dec".
    5. I add a new column "Pivot Headers" that pulls text after delimiter " " (a single space). This isolates "Organic" & "Promo"
    6. I delete the "Attribute" column
    7. I select "Pivot Headers" and pivot, choosing my value column as... the value column.

     

    In general, you're wanting to unpivot and then re-pivot. The key is to get your desired resulting pivoted headers into a single "Pivot Headers" column. So if you want to end up with 4 groups of values, the "Pivot Headers" needs to have the 4 distinct values.