Forum Discussion
Unpivot several columns with attribute and value
- 2 years ago
i take these example
ok problem solve follow below step
1. select ID Articolo and unpivote other column
2. replace value code mat1, code mat2, code mat3, code amt4 to code
and qt mat1, qt amt2, qt amt3, qt mat4 to qt
3. add conditional column like these
which look like these
4. add another conditional column like these
5. copy qt column and paste to new table(qt table) and add index column which look like below
6. now return to original table and add index to original table
7. now merge original table and qt tqble
8. now expand table click on rounded(red) area
by clicking red area open interface and from that unselect index column
press ok which look like these
9. change qt table name to qt and select Id Articolo, code and qt and remove other column and it look like these
10. now filter table and which show those value non-null value
and it look like these
here solution done
don't get confuse with values because i take some different value from you but following my step you got your answer here t attach step screenshort for comfortness
close and apply from home tab and paly with it
Did i answer your question? Mark my post as a solution which help other people to find fast and easily.
I apologize for the misunderstanding. Based on your clarification, you want the result where the code and quantity are in separate columns. To achieve this, you can use Power Query in Power BI or Excel with the following steps:
Assuming your original table looks like this:
```
CodeArticle | Material1 | Quantity1 | Material2 | Quantity2 | ...
--------------------------------------------------------------
A1 | M1 | 10 | M2 | 15 | ...
B2 | M3 | 20 | M4 | 25 | ...
...
```
You want to transform it into the following format:
```
CodeArticle | Material | Quantity
--------------------------------
A1 | M1 | 10
A1 | M2 | 15
B2 | M3 | 20
B2 | M4 | 25
...
```
Follow these steps:
1. **Load your data into Power Query**:
- In Power BI: Go to the Power Query Editor by selecting the "Edit Queries" option in the Home tab.
- In Excel: Go to the Data tab and select "Get Data" > "Combine Queries" > "Merge Queries."
2. **Use "Unpivot Other Columns"**:
- In Power Query, select the "CodeArticle" column and right-click, then choose "Unpivot Columns" > "Unpivot Other Columns." This will unpivot all columns except the "CodeArticle" column.
3. **Rename Columns**:
- Rename the "Attribute" column to "Material."
- Rename the "Value" column to "Quantity."
4. **Load the Transformed Data**:
- In Power Query, click "Close & Apply" to load the transformed data back into your Power BI dataset.
- In Excel, you can load the data to a new worksheet or overwrite the existing data, depending on your preference.
After these steps, you will have the desired result where the "CodeArticle," "Material," and "Quantity" are in separate columns.