Search code examples
powerquery

Power query - How can i merge all columns except for column name "Custom"


My power query table has an unknown number of columns upon refresh, all columns with type decimal except for a single column name "Custom" which is type Number. I want to be able to merge all columns except for the "Custom" column. I cannot select the columns and do it because in the next refresh the column names might be different

  1. I first created a list to get all existing column names apart from "Custom" as follows
= List.Select(Table.ColumnNames(ConveretedtoDecimal), each _ <> "Custom")

This works and generates the correct list of column names

  1. Then i tried the following (as suggested by Chat GPT), but it does not work
=Table.TransformColumns(ConvertedtoDecimal, {{"Custom", each Text.Combine(List.Transform(columnsToMerge, each Text.From(_)), ""), type text}})

Solution

  • If I understand correctly, and you want to combine these numeric columns as text strings with no separator, then you could use this snippet:

        #"Cols to Merge" = List.RemoveItems(Table.ColumnNames(#"Previous Step"),{"Custom"}),
    
    //Change merge columns to text, then combine them with no delimiter
        #"Type Merge as Text" = Table.TransformColumnTypes(#"Previous Step",
                    List.Transform(#"Cols to Merge", each {_, type text})),
                    
        #"Merged Columns" = Table.CombineColumns(#"Type Merge as Text",
            #"Cols to Merge",
            Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Merged")
    
    • Set the data type of the decimal columns to text
    • Then combine the columns with "" as the delimiter