Forum Discussion

antepenultimate's avatar
antepenultimate
New Member
3 years ago

Replacing Monthly File with next 12 months creates new header names each month

I have a forecast file that I connect to my data model and its very simple:

SKU | Channel | M1 | M2 | M3 |...| M12 |

But I have the actual MM/DD/YYYY as the column headers so each month, M1-M12 changes.

 

The steps I run in the query just unpivot the months, but every time I replace the file the following month I get the error that it doesn't recognize the header its looking for. I've tried pasting a fake additional header on the first row and then make my first step be "Promote Headers" but that doesn't seem to work. 

 

There has to be something simple here I am missing.


Example:

This Month:

SKULocation9/1/202310/1/202311/1/202312/1/2023
Product AEast3.30093.26243.22393.1854
Product AWest0000
Product BEast0.3888890.3888890.3888890.388889
Product BWest0000
Product CEast0000
Product CWest1.912011.873511.835011.79651

 

 

 

 

Next Month:

SKULocation10/1/202311/1/202312/1/20231/1/2024
Product AEast3.26243.22393.18543.1469
Product AWest0000
Product BEast0.3888890.3888890.3888890.388889
Product BWest0000
Product CEast0000
Product CWest1.873511.835011.796511.75801

 

4 Replies

  • Hi antepenultimate ,

     

    Use Unpivot Other Columns instead of Unpivot Columns:

     

    Multi-select (Ctrl+click) [SKU] and [Location].

    Go to the Transform tab > Unpivot Columns (dropdown) > Unpivot Other Columns.

     

    Power Query will now ignore the column names of those it is unpivoting and instead only hardcode those you intially selected.

     

    Pete

    • antepenultimate's avatar
      antepenultimate
      New Member

      This sounds pretty good. So the selections are the only column headers that it looks at?

      • BA_Pete's avatar
        BA_Pete
        Icon for Super User rankSuper User

         

        Correct. The selected columns are the only ones that get hardcoded, the rest get unpivoted as required.

         

        Pete

  • HopkiJ's avatar
    HopkiJ
    Frequent Visitor

    Have you put all months into your table in the source data? If the transform file table is different everytime it refreshes this will cause issues with your query as it'll always look for the original format. May be worth taking the months out two or three years on the original table and hopefully it should load correctly moving forward.