Forum Discussion

PBIDevNoob's avatar
PBIDevNoob
Helper I
7 years ago
Solved

Combine/Merge multiple columns based on its name

Hi!   I need a power query / M query that can combine multiple columns with similar names.   Let's say I have the following columns:     I want to combine: "Start Date-Month_1" with "Start...
  • v-juanli-msft's avatar
    7 years ago

    Hi PBIDevNoob 

    In Edit queries, add an index column, click on the "index column", then select "unpivot other columns".

     

    Add column->Extact->"Text After Delimiter"/"Text Before Delimiter"

    #"Inserted Text After Delimiter" = Table.AddColumn(#"Unpivoted Other Columns", "Text After Delimiter", each Text.AfterDelimiter([Attribute], "_"), type text),
    #"Inserted Text Before Delimiter" = Table.AddColumn(#"Inserted Text After Delimiter", "Text Before Delimiter", each Text.BeforeDelimiter([Attribute], "-"), type text),

    Add column->Merge columns

    Remove useless columns

    To make the "start date" and "end date" as columns name, click on the column, select "pivot columns"

    Best Regards
    Maggie

     

    Community Support Team _ Maggie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.