Power Query dynamic columns

Copper Contributor
I need to create a budget file with sales quantities, which I need to multiply with a different unit of measurement.
The base file has 5 years of data split by month. From this file I just need 1 year (12 columns). To keep it flexible, I have created a list with column names, that I need for the project. This list is called "SelectedHeaders". This column name list is used to select the columns, groupings, roundings etc.
The quantity fields are called "Forecast - Month Year" and the multiply column is called "ReportingActivity".
I want to replace the values, so I used the following formula which is working:
= Table.ReplaceValue(#"Changed Type",0,each [ReportingActivity],(a,b) => a*b ,{"Forecast  - Jan 22"})
The question is, how can I use the "SelectedHeaders" list instead of fixing the column names like {"Forecast  - Jan 22"}
2 Replies

@Andre_nl So you have 60 columns of data (5 years, 12 months each)? Perhaps better to unpivot these columns first and then do your analysis/calculations based on the selected periods. But perhaps I misunderstood your question altogether. 

I have tried that on a payroll file with 350 employees. 15-20 lines per employee and roughly 50 columns, but the issue is that that route is just to slow to work with and on updating the data.
The current file is actually 72 month colums+ 10 or so for item, item classifications and sales regions. Number of lines in the database is over 50.000. (It is a csv file of approx 20Mb)
After the calculations, I need to unpivot this dataset again as I need the months as columns.
I select the required columns based on the headerlist and it works fine. Also used the headlist to round and change the colums types, but on I cant get it to work on this step.