Forum Discussion
Transpose & Pivot using Power Query
- Anonymous1 year ago
Hi arimoldi
Excel
I retested your problem by first importing the excel table into the power bi desktop and going to the power query interface to get the following table:
1. If you don't want empty values to display data, consider replacing "null" with Spaces.
In the same step, you just need to change the "0" to " ".
Use the first line as the title.
Delete "Changed Type1" from the step bar on the right.
2. Select the first column and click Fill -> Down. The first column will be filled in automatically.
Finally, the column with the date header is also selected for unpivot.
Change the column name as required.
Regards,
Nono Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Yes you can do this with the help of Pivot and Unpivot data in power query.
1.Go to Power BI Power Query Editor.
2.Then go to Transform Option.
3. Under Any Column Group there are many opitons but two are for you a: Unpivot Columns, b: Pivot Coumn.
4. Unpitovt Columns will solve your issue.
Please follow below detail:
Load the Data into Power Query:
- Load your data into Power Query Editor by selecting your data range and choosing "Data" > "From Table/Range" in Excel (make sure your data is in a table format).
Unpivot the Data:
- In Power Query Editor, select the date columns (e.g., 01/10/2024, 02/10/2024, etc.).
- Go to the Transform tab and select Unpivot Columns. This will create three columns: ACTIVITY, Attribute, and Value.
Rename Columns:
- Rename the Attribute column to DATE.
- Rename the Value column to NUM.
Set Data Types:
- Ensure that the DATE column is set to the Date data type, and the NUM column is set to the Whole Number data type (or Decimal, depending on your data).
Sort (Optional):
- You may want to sort the table by DATE and then by ACTIVITY to get the desired order.
Close & Load:
- Click Close & Load to load the transformed data back into Excel or Power BI.
Result
You should now have your data in the desired format:
DATE ACTIVITY NUM
| 01/10/2024 | A | 8 |
| 01/10/2024 | B | |
| 01/10/2024 | C | |
| 01/10/2024 | D | |
| 01/10/2024 | E | |
| 01/10/2024 | F | |
| 02/10/2024 | A | |
| 02/10/2024 | B | 3 |
| ... | ... | ... |
This unpivoting technique transforms your wide format into the desired long format with columns for DATE, ACTIVITY, and NUM.