Forum Discussion

siva_powerbi's avatar
siva_powerbi
Helper IV
5 years ago
Solved

Concatenating dynamic column name to table - Power Query

I am trying to create lists of data using dynamic columns, fetching the column name and appending it to the table.

 

Here is the problem as this step is throwing error:

 

Expression.Error: We cannot apply operator & to types Table and Text.

 

Details:
Operator=&
Left=[Table]
Right=Test1

 

Code:

 

let
Source = Excel.Workbook(File.Contents("C:\Users\Sivakumar A\Desktop\Power BI\test1.xlsx"), null, true),
Sheet2_Sheet = Source{[Item="Sheet2",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Sheet2_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Test1", type text}, {"Test2", Int64.Type}, {"Test3", Int64.Type}, {"Test4", Int64.Type}}),
#"Col Names" = Table.ColumnNames(#"Changed Type"),
#"Generate" = List.Generate(() => [i=-1,x= Table.FromList(#"Col Names",Splitter.SplitByNothing())],
each [i]<List.Count(#"Col Names"),
each [
i=[i]+1,
x=#"Promoted Headers"&#"Col Names"{i}

],
each [x])
in
Generate

 

I need to extract the column names and append it to the talble and execute in loop

 

Any help is appretiated.

  • @MFelix Thanks for referring the post.

    I was able to solve the issue using double quite 3 times.

    "Table.Distinct(Table.FromList(#"&"""Sheet2 (2)"""&"["&#"Col Names"{i}&"], Splitter.SplitByNothing(), null, null, ExtraValues.Error))"

2 Replies

    • siva_powerbi's avatar
      siva_powerbi
      Helper IV

      @MFelix Thanks for referring the post.

      I was able to solve the issue using double quite 3 times.

      "Table.Distinct(Table.FromList(#"&"""Sheet2 (2)"""&"["&#"Col Names"{i}&"], Splitter.SplitByNothing(), null, null, ExtraValues.Error))"