It sounds like you've encountered an issue where, after pivoting, the values in the new column are showing as numbers instead of the actual goal names, statuses, or terms. This can happen if Power Query interprets the values incorrectly during the pivoting process.
To clarify, let's go through the steps carefully and adjust accordingly, ensuring that we end up with the correct data format — specifically, ensuring that the values in your final dataset are your original goal names, statuses, and terms rather than numerical indices or aggregate values.
Steps to Correctly Unpivot and Pivot Data in Power Query
-
Load Original Data: Make sure your starting dataset is correctly imported into Power Query with the following structure:
| PID | goal_1 | goal_2 | goal_3 | status_1 | status_2 | status_3 | term_1 | term_2 | term_3 |
|---|
| 1 | G1 | G2 | G3 | Completed | Ongoing | Pending | 2021 | 2022 | 2023 |
| 2 | G4 | G5 | G6 | Completed | Completed | Ongoing | 2024 | 2025 | 2026 |
| 3 | G7 | G8 | G9 | Pending | Ongoing | Completed | 2027 | 2028 | 2029 |
-
Unpivot Goal Columns:
-
Select the three columns for goals (goal_1, goal_2, goal_3).
-
Right-click on one of the selected headers and choose Unpivot Other Columns.
-
This will produce:
| PID | Attribute | Value |
|---|
| 1 | goal_1 | G1 |
| 1 | goal_2 | G2 |
| 1 | goal_3 | G3 |
| 2 | goal_1 | G4 |
| 2 | goal_2 | G5 |
| 2 | goal_3 | G6 |
| 3 | goal_1 | G7 |
| 3 | goal_2 | G8 |
| 3 | goal_3 | G9 |
-
Rename the Columns:
- Rename the
Attribute column to Type or something appropriate, but it's not strictly necessary for this step.
-
Keep Only Goal Data:
- Filter the
Type column to include only rows with goal.
-
Create Additional Queries for Status and Term:
- You should repeat the unpivoting process for the
status and term columns. For the status columns:
- Select the three columns for statuses (
status_1, status_2, status_3).
- Right-click and choose
Unpivot Other Columns, yielding similar results.
- Do the same for the
term columns, allowing you to have separate tables for each.
-
Merge Data:
- After you've unpivoted all relevant columns, you may need to merge the resulting queries based on the
PID and the index to ensure you're aligning the correct goal with its corresponding status and term.
- You can create an index column in each of the unpivoted tables so that each row can be matched correctly. This will help you cross-reference them based on their order (i.e., the first goal corresponds to the first status and the first term).
-
Final Reshape:
- After merging the tables, you'll create a combined view with columns for
PID, Goal, Status, and Term.
Example of Final Result
Your final combined dataset should look like this:
| PID | Goal | Status | Term |
|---|
| 1 | G1 | Completed | 2021 |
| 1 | G2 | Ongoing | 2022 |
| 1 | G3 | Pending | 2023 |
| 2 | G4 | Completed | 2024 |
| 2 | G5 | Completed | 2025 |
| 2 | G6 | Ongoing | 2026 |
| 3 | G7 | Pending | 2027 |
| 3 | G8 | Ongoing | 2028 |
| 3 | G9 | Completed | 2029 |
Important Tips
- If numbers are showing after a pivot, ensure you are not aggregating values. The Pivot Column option should allow you to choose the values but keep the original string values.
- Use the Data Type settings in Power Query to ensure that your columns are text if needed.
- After merging the queries, make sure to adjust each merged table appropriately. You may need to change column names and data types.
By following this process carefully, you should be able to get rid of any numerical values in your columns and reconstruct the original string values based on your goals, statuses, and terms.