Power Query - Change Type Dynamically

gelu

Board Regular
Joined
Sep 30, 2022
Messages
85
Office Version
  1. 2021
Platform
  1. Windows
Hello there,

I would appreciate your help on the following.

Detect data type dynamically.

I deal with changing file formats and tables sizes.
When detecting data types I would like to tell PQ to take whatever columns are there and deal with each of them accordingly (instead of hard coded column names as it does by default).

What I do:

1 - I load one file to PQ from folder (there is always just one file but it could be .txt .csv .xls .xlsx or whatever else).

2 - I keep generic column headings when combining the files (by selecting "Do not detect data types"

1706692535532.png



3 - In the example below the table has 9 columns. But next time it could have 3 or 25 ...


Rich (BB code):
let
    Source = Csv.Document(Parameter1,[Delimiter="#(tab)", Columns=9, Encoding=1252, QuoteStyle=QuoteStyle.None]),
    #"Change Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, _
    {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}, _
    {"Column7", type text}, {"Column8", type text}, {"Column9", type text}})
in
    #"Change Type"


How to do this dynamically?
 
Last edited:
I tried it directly on a text file and it didn't do anything because the data was all already imported as text, not as any.
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,215,076
Messages
6,122,988
Members
449,093
Latest member
Mr Hughes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top