Forum Discussion
Union columns with changing values
Hi all,
I am looking for a solution(with DAX) to union a few columns in the same table(A,B,C), meanwhile, changing the values to the column name if it is "fail".
Orginal:
| Item | A | B | C |
| 1 | Pass | Fail | Pass |
| 2 | Fail | Pass | Fail |
desired output: (replace the value with column name if it is fail)
| Item | Appended |
| 1 | Pass--> null |
| 2 | Fail --> A |
| 1 | Fail --> B |
| 2 | Pass--> null |
| 1 | Pass--> null |
| 2 | Fail --> C |
Hi ngct1112
Try this code to add a new table:
Table 2 = union( SELECTCOLUMNS('Table',"Item",[Item],"Appended",if([A]="Fail","A",[A])), SELECTCOLUMNS('Table',"Item",[Item],"Appended",if([B]="Fail","B",[B])), SELECTCOLUMNS('Table',"Item",[Item],"Appended",if([C]="Fail","C",[C])) )Output:
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
3 Replies
- Jihwan_Kim
Super User
Hi,
I am not sure if I understood your question correctly, but please check the below picture.
It is for the table creation.
New Table =UNION (SUMMARIZECOLUMNS (Data[Item],"Appended", IF ( MAX ( Data[A] ) = "Pass", "null", "A" )),SUMMARIZECOLUMNS (Data[Item],"Appended", IF ( MAX ( Data[B] ) = "Pass", "null", "B" )),SUMMARIZECOLUMNS (Data[Item],"Appended", IF ( MAX ( Data[C] ) = "Pass", "null", "C" ))) - VahidDM
Super User
Hi ngct1112
Try this code to add a new table:
Table 2 = union( SELECTCOLUMNS('Table',"Item",[Item],"Appended",if([A]="Fail","A",[A])), SELECTCOLUMNS('Table',"Item",[Item],"Appended",if([B]="Fail","B",[B])), SELECTCOLUMNS('Table',"Item",[Item],"Appended",if([C]="Fail","C",[C])) )Output:
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!