Forum Discussion

Andrew415's avatar
Andrew415
Frequent Visitor
1 year ago
Solved

Pivoting Multiple Columns More Efficiently

Hi, I am trying to find a more efficient way to multiple pivot columns in Power Query from a shipping report. I'm currently selecting each pair of columns (description and adjacent amount), pivoting the columns, and then removing the empty column from the pivoted pair.

 

A couple of my headaches with the raw data is

1) headers for the "tracking ID charge descriptions" and amounts are not static ("charge description_3" might say remote residential one week, and then fuel surcharge another week)

2) there are ~100 columns of "charge description" and "charge amount" that need to be paired together, and most will be completely null/empty

 

Data sample

Tracking IDDateTracking ID Charge DescriptionTracking ID Charge AmountTracking ID Charge Description_1Tracking ID Charge Amount_2Tracking ID Charge Description_3Tracking ID Charge Amount_4Tracking ID Charge Description_104Tracking ID Charge Amount_105Tracking ID Charge Description_106Tracking ID Charge Amount_107
1231/1/2025  Fuel Surcharge1.25Remote Residential15    
2341/7/2025  Fuel Surcharge3.4  Address Correction13.5  
3451/21/2025Extended Residential7Fuel Surcharge2.1  Address Correction13.5  
5671/28/2025  Fuel Surcharge4.5  Address Correction13.5  
4562/6/2025  Fuel Surcharge8.2Remote Residential15Address Correction13.5  
6782/12/2025  Fuel Surcharge2.4      
8902/19/2025  Fuel Surcharge1.3      
9012/27/2025Extended Residential7Fuel Surcharge6.5      

 

End-state

Tracking IDDateExtended ResidentialFuel SurchargeRemote ResidentialAddress Correction
1231/1/2025 1.2515 
2341/7/2025 3.4 13.5
3451/21/202572.1 13.5
5671/28/2025 4.5 13.5
4562/6/2025 8.21513.5
6782/12/2025 2.4  
8902/19/2025 1.3  
9012/27/202576.5  

7 Replies

  • Irwan's avatar
    Irwan
    Super User

    hello Andrew415 

     

    i dont know how many column you want to show in your visual.

    if your visual only contain couple columns such as Extended Residential, Fuel Surcharge, Remote Residential, and Address Correction, maybe measure should be sufficient for those four instead of unpivoting ~100 columns.

     

    Hope this will help.

    Thank you.

  • Andrew415's avatar
    Andrew415
    Frequent Visitor

    Would it be possible to list the measure here as text? I'll give it a go and see if it might help. The blank columns wouldn't need to be part of the visual

    • Irwan's avatar
      Irwan
      Super User

      hello Andrew415 

       

      i am not sure why you want it as text but perhaps it is possible.

      you can tweak the DAX however you want to match up your requirement including the blank column.

       

      otherwise, try using SundarRaj 's solution. it surely gives your broader insight of your case.

       

      Thank you.

    • Andrew415's avatar
      Andrew415
      Frequent Visitor

      Thank you, this works perfectly for what I am trying to accomplish.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Andrew415,

    As we haven’t heard back from you, we would like to follow up to see if the solution provided by the super user resolved your issue. Please let us know if you need any further assistance.
    If our super user response resolved your issue, please mark it as "Accept as solution" and click "Yes" if you found it helpful.

     

    Regards,
    Vinay Pabbu

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi @Andrew415,

      As we haven’t heard back from you, we would like to follow up to see if the solution provided by the super user resolved your issue. Please let us know if you need any further assistance.
      If our super user response resolved your issue, please mark it as "Accept as solution" and click "Yes" if you found it helpful.

       

      Regards,
      Vinay Pabbu