Forum Discussion

Meindert's avatar
Meindert
New Member
4 years ago
Solved

Looping through columns in table

Hi everyone,   I have the following problem. My datasource, an Excel file, exists out of 101columns. As from column 20 I want to merge 2 columns at the time.  So the data in column 20 and column ...
  • Meindert's avatar
    4 years ago

    Hi,

     

    I've been testing around, after a friend told me a way to incoorporate loops in M and this is what I found myself.

     

    MergedColumns = List.Accumulate(

            {7..40}, #"Changed Type",(state,current) 

            => Table.CombineColumns(state,

                                    {"Column" & Number.ToText(current*2-1), "Column" & Number.ToText(current*2) },

                                    Combiner.CombineTextByDelimiter("||",QuoteStyle.None),

                                    "Column"& Number.ToText(current*2-1))

            )

     

    And this works. It merges all columns between number 13 and 80 and gives them correct names.

     

    Cheers

    Meindert