Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
JamesT23
Frequent Visitor

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

 

1 ACCEPTED SOLUTION
v-xicai
Community Support
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"<>"")

 

4.png 

 

 

 

 

 

Then, create column Vendor_Concatenate in Table2.

 

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

 

5.png 

 

 

 

 

Here is my test pbix: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EdlYsKW-CSJLjxmFNN...

 

Best Regards,

Amy

 

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

View solution in original post

2 REPLIES 2
v-xicai
Community Support
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"<>"")

 

4.png 

 

 

 

 

 

Then, create column Vendor_Concatenate in Table2.

 

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

 

5.png 

 

 

 

 

Here is my test pbix: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EdlYsKW-CSJLjxmFNN...

 

Best Regards,

Amy

 

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

Thanks Amy! 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.