# merge multiple variable columns in Power Query



## johnmpl (Feb 8, 2016)

Hi to all!

How can I merge multiple and variable (sometimes was 3, anothers 0, anothers 10) columns into one using Power Query?

I know how to merge columns, but no when the number of columns is variable.

Thx for all your responses.


----------



## ImkeF (Feb 8, 2016)

Assuming that you want to apply the merge on all columns of the current table (otherwise: how do you intend to select the columns?), this code would do:


```
let
    Source = Excel.CurrentWorkbook(){[Name="Tabelle1"]}[Content],
    ColNames = Table.ColumnNames( Source),
    TransformCommand = List.Transform(ColNames, each {_, type text}),
    #"Changed Type1" = Table.TransformColumnTypes(Source, TransformCommand),
    #"Merged Columns" = Table.CombineColumns(#"Changed Type1", ColNames,Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Merged")
in
    #"Merged Columns"
```

It generates a list of all column names for the merge and also changes all column types to text before the merge, because non-text columns would cause Errors.


----------



## johnmpl (Feb 8, 2016)

Great ImkeF!

With your code... I solved my issue.  Blessings and thx!


----------

