Forum Discussion
pivot/unpivot table using DAX
Hello, can somebody help me to create new table using DAX with filters and calculations please.
I have a table as follows:
| Date | Client | Type | Item | Value |
| 1/12/2022 | client | type 1 | item 1 | 5 |
| 2/12/2022 | client | type 1 | item 1 | 5 |
| 3/12/2022 | client | type 1 | item 1 | 5 |
| 1/12/2022 | client | type 2 | item 2 | 5 |
| 2/12/2022 | client | type 2 | item 2 | 5 |
| 3/12/2022 | client | type 2 | item 2 | 5 |
| 1/12/2022 | client | type 3 | item 1 | 5 |
| 2/12/2022 | client | type 3 | item 1 | 5 |
| 3/12/2022 | client | type 3 | item 1 | 5 |
| 1/12/2022 | client | type 4 | item 2 | 5 |
| 2/12/2022 | client | type 4 | item 2 | 5 |
| 3/12/2022 | client | type 4 | item 2 | 5 |
| 1/12/2022 | client | type 5 | item 3 | 0 |
| 2/12/2022 | client | type 5 | item 3 | 0 |
| 3/12/2022 | client | type 5 | item 3 | 0 |
| 1/12/2022 | client | type 5 | item 4 | 0 |
| 2/12/2022 | client | type 5 | item 4 | 0 |
| 3/12/2022 | client | type 5 | item 4 | 0 |
| 1/12/2022 | client | type 5 | item 5 | 0 |
| 2/12/2022 | client | type 5 | item 5 | 0 |
| 3/12/2022 | client | type 5 | item 5 | 0 |
and I need to achieve data in a new table as below using DAX only:
| Date | Client | Type | item 1 | item 2 | item 3 | item 4 | item 5 | Totals |
| 1/12/2022 | client | type 5 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1/12/2022 | client | type 4 | 0 | 5 | 0 | 0 | 0 | 5 |
| 1/12/2022 | client | type 3 | 5 | 0 | 0 | 0 | 0 | 5 |
| 2/12/2022 | client | type 5 | 0 | 0 | 0 | 0 | 0 | 0 |
| 2/12/2022 | client | type 4 | 0 | 5 | 0 | 0 | 0 | 5 |
| 2/12/2022 | client | type 3 | 5 | 0 | 0 | 0 | 0 | 5 |
| 3/12/2022 | client | type 5 | 0 | 0 | 0 | 0 | 0 | 0 |
| 3/12/2022 | client | type 4 | 0 | 5 | 0 | 0 | 0 | 5 |
| 3/12/2022 | client | type 3 | 5 | 0 | 0 | 0 | 0 | 5 |
So basically, I need to filter "Type" column by type3, type 4, type 5 and Pivot "Item" & "value" columns by "Value" and create a new column called "Totals". So the Total column will be Sum(Item)
I know this will be easy doing in Power Query, by I want to achieve this with DAX.
TIA
1 Reply
- amitchandakSuper User
jaipalambati , You can display that in Matrix like that. That should be best
If you still need pivot.
In DAX we do not have a pivot. You have to create measures for each one of those
Item 1= calculate(Sum(Table[Value]), filter(Table, Table[Item] = "Item 1") )
You can create other measures