Forum Discussion

JamesT23's avatar
JamesT23
Frequent Visitor
7 years ago
Solved

DAX Unpivot

Hi 

 

I have a set of data i need to unpivot in two ways and don't seem to be able to do it. Can someone help me. I do this in SQL currently using AS and UNION but need to tansfer to power query.

 

CompanyDateVendor 1Vendor 2Vendor 3Charge Type 1Charge Type 2Charge Type 3Charge 1Charge 2Charge 3
Dell2018HPEpsonCiscoPrintersCameraSwitch100200150
Dell2019MicrosoftEpsonHPLicensesCameraServer150200350

 

This is how i need one result to look 

 

CompanyDateVendorCharge TypeCharge
Dell2018HPPrinters100
Dell2018EpsonCamera200
Dell2018CiscoSwitch150
Dell2019MicrosoftLicenses150
Dell2019EpsonCamera200
Dell2019HPServer350

 

 

This is how i need the send to look where i concat Vendor and charge types. 

CompanyDateVendorCharge
Dell2018HP-Printers100
Dell2018Epson-Camera200
Dell2018Cisco-Switch150
Dell2019Microsoft-Licenses150
Dell2019Epson-Camera200
Dell2019HP-Server350

 

Please also be aware in your solution that sometimes I need to join Vendor 1 with Charge Type 2

 

  • Hi JamesT23 ,

     

    You can create new Table2.

     

    Table2 =

    FILTER(

    UNION(

    SELECTCOLUMNS('Table1',"Company",[Company],"Date",[Date],"Vendor",[Vendor 1],"Charge Type",[Charge Type 1],"Charge",[Charge 1]),

    SELECTCOLUMNS('Table1',"Company",[Company],"Date",[Date],"Vendor",[Vendor 2],"Charge Type",[Charge Type 2],"Charge",[Charge 2]),

    SELECTCOLUMNS('Table1',"Company",[Company],"Date",[Date],"Vendor",[Vendor 3],"Charge Type",[Charge Type 3],"Charge",[Charge 3])

    ),

    "Vendor"<>""&&"Charge Type"<>""&&"Charge"<>"")

     

     

     

     

     

     

     

    Then, create column Vendor_Concatenate in Table2.

     

    Vendor_Concatenate = CONCATENATE(Table2[Vendor],Table2[Charge Type])

     

     

     

     

     

     

    Here is my test pbix: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EdlYsKW-CSJLjxmFNNdjGmsBdouyugHjnZ3DiNCBIiMd9Q?e=rYtfpc

     

    Best Regards,

    Amy

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

2 Replies

  • v-xicai's avatar
    v-xicai
    Community Support

    Hi JamesT23 ,

     

    You can create new Table2.

     

    Table2 =

    FILTER(

    UNION(

    SELECTCOLUMNS('Table1',"Company",[Company],"Date",[Date],"Vendor",[Vendor 1],"Charge Type",[Charge Type 1],"Charge",[Charge 1]),

    SELECTCOLUMNS('Table1',"Company",[Company],"Date",[Date],"Vendor",[Vendor 2],"Charge Type",[Charge Type 2],"Charge",[Charge 2]),

    SELECTCOLUMNS('Table1',"Company",[Company],"Date",[Date],"Vendor",[Vendor 3],"Charge Type",[Charge Type 3],"Charge",[Charge 3])

    ),

    "Vendor"<>""&&"Charge Type"<>""&&"Charge"<>"")

     

     

     

     

     

     

     

    Then, create column Vendor_Concatenate in Table2.

     

    Vendor_Concatenate = CONCATENATE(Table2[Vendor],Table2[Charge Type])

     

     

     

     

     

     

    Here is my test pbix: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EdlYsKW-CSJLjxmFNNdjGmsBdouyugHjnZ3DiNCBIiMd9Q?e=rYtfpc

     

    Best Regards,

    Amy

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.