Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago

Concatenate two column and create a new column using Power Query

Hi Experts,

I am trying to concanate two column using power query. I am unable to get the output. I have "Month" and "Year" two separate columns in my calender table. I wanted to merge those two columns and get the output like, "2019-Jan"

 

this is my script for same:

 

= Table.AddColumn(#"Changed Type2", "YYYYMM", each [Fin Month] & [Fin Year])

 

I am getting "error" as my column value.

 

I even tried to create a new columns using power query script directly from the "advanced editor"

 

#"Inserted MonthYearLong" = Table.AddColumn(#"Inserted MonthYearLong", "Year Month", each [Month] & "-" & Text.From([Year])),

 

I am not sure whats the best way to get output like 2019-Jan!

 

Would appreciate your help.

 

Thanks in advance.

 

 

 

 

 

 

 

2 Replies

  • Zubair_Muhammad's avatar
    Zubair_Muhammad
    Community Champion

    Anonymous 

     

    You cannot refer same step's name inside the expression.

    Use the previous step name

     

    #"Inserted MonthYearLong" = Table.AddColumn(#"Inserted MonthYearLong", "Year Month", each [Month] & "-" & Text.From([Year])),
    • Anonymous's avatar
      Anonymous
      Not applicable
      Hi Zubair Thanks for your response in relation to my above query. Now Ive referred previous step name. But still I am getting this error; Expression.Error: The column 'YYYYMM' of the table wasn't found. Details: YYYYMM #"Inserted First Characters1" = Table.AddColumn(#"Inserted First Characters", "DDD", each Text.Start([Day Name], 3), type text), #"Inserted MonthYearLong" = Table.AddColumn(#"Inserted First Characters1", "Year Month", each [Month] & "-" & Text.From([Year])), But I am getting error while I am trying to record the column details; #"Reordered Columns" = Table.ReorderColumns(#"Inserted First Characters1",{"Date", "Fin Year", "Month Name", "MMM", "YYYYMM", "Fin Month", "Day Name", "DDD", "Day of Week"}),