Forum Discussion
Pivot multiple value types and KPIs
- 1 year ago
Hi JK07 ,
You are right. Apologies for that, and instead of using the fill up, you can use Groupby function in Power Query to restructure the table like below:
The above was prepared by clicking the ribbon for each new column one at a time, but there might be a more efficient way to do this, even for the initial setup.
I have attached the PBIX file for your reference.
Hi JK07 ,
You can rearrange your data in your desired format using Power Query by following these steps:
- Pivot the [Value type] column: This will create separate columns for each value type ("Actual," "Budget," "Commitment," and "On hold") with 1s and 0s indicating their presence.
= Table.Pivot(#"Changed Type1", List.Distinct(#"Changed Type1"[#"Value type"]), "Value type", "ID", List.Count)
- Add columns: Multiply the original value columns by the newly created columns of 1s and 0s for each value type to place the values in the appropriate columns. This process requires repetitive work, and there might be more efficient methods than manually adding a custom column for each combination of value type and value one by one.
- Replace 0s with nulls: In the new columns containing values, replace 0s with nulls, and use the fill-up feature to propagate the values.
- Filter for First Occurrence: In the value type field, filter for the first occurrence of 1 in the top row to remove duplicates.
- The final output: Your data will be rearranged as shown below.
These steps can be performed by clicking the Power Query ribbons.
Best regards,
Hi DataNinja777
Thanks, I stuck on #3 and filtering. Can you please explain more how to do it and keep all populated values in each column?
Best,
- DataNinja7771 year agoSuper User
Hi JK07 ,
1. Select the Column: Click on the column header that contains the values you want to fill up.
2. Go to the Transform tab: In the Power Query Editor, navigate to the Transform tab in the ribbon.
3. Use the Fill option:
- In the Transform tab, look for the Fill button. It is usually located in the Any Column group.
- Click on the drop-down arrow next to the Fill button.
- You will see two options: Fill Down and Fill Up.
- Select Fill Up.
4. Apply Changes: Once you select Fill Up, Power Query will fill the empty cells in the selected column by propagating the nearest non-empty value upwards.
5. To retain only the non-duplicate rows, select the 'Budget' column and filter for the value '1'. This works because the 'Budget' column has a '1' in the top row, and we are using the Fill Up feature to propagate values. By filtering for '1' in the 'Budget' column, we ensure that only non-duplicate rows are kept.
Best regards,
- JK071 year agoNew Member
DataNinja777 hi,
Thanks, It seems it doesnt work for last ID (D). After filtering I get null in Actuals, same in On Hold, etc.
Also ID C should have 39585 in Actual Company while it gets 822 (so ID D value)
Best,
- DataNinja7771 year agoSuper User
Hi JK07 ,
You are right. Apologies for that, and instead of using the fill up, you can use Groupby function in Power Query to restructure the table like below:
The above was prepared by clicking the ribbon for each new column one at a time, but there might be a more efficient way to do this, even for the initial setup.
I have attached the PBIX file for your reference.