Forum Discussion
Create a new table with column names
I have a table that contains at least 3 columns, but from the 3rd it has names like A.21 B.22 ..., and I want to have a new table with a column Names that have the names of the columns that have the format x.xx (always there is a point), how can I write that condition or regex?
In Power Query, duplicate the query for the table. Then select the column you need and select Remove other columns under Remove in the ribbon. Select the column and select Pivot, and finally select promote as headers
Hi nicolasvc ,
Take below table for example:
Go to query editor>create a blank query using below M codes:
let Source = Table.ColumnNames(#"Table"), #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error), #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Select([Column1],{"A".."z","0".."9"})), #"Split Column by Position" = Table.SplitColumn(#"Added Custom", "Custom", Splitter.SplitTextByPositions({0, 1}, false), {"Custom.1", "Custom.2"}), #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Position",{{"Custom.1", type text}, {"Custom.2", Int64.Type}}), #"Added Custom1" = Table.AddColumn(#"Changed Type1", "Custom", each [Custom.1]&"."&Number.ToText([Custom.2])), #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Custom.1", "Custom.2"}) in #"Removed Columns"And you will see:
For the related .pbix file,pls see attached.
Best Regards,
KellyDid I answer your question? Mark my raeply as a solution!
2 Replies
- PaulDBrownCommunity Champion
In Power Query, duplicate the query for the table. Then select the column you need and select Remove other columns under Remove in the ribbon. Select the column and select Pivot, and finally select promote as headers
- v-kelly-msftCommunity Support
Hi nicolasvc ,
Take below table for example:
Go to query editor>create a blank query using below M codes:
let Source = Table.ColumnNames(#"Table"), #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error), #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Select([Column1],{"A".."z","0".."9"})), #"Split Column by Position" = Table.SplitColumn(#"Added Custom", "Custom", Splitter.SplitTextByPositions({0, 1}, false), {"Custom.1", "Custom.2"}), #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Position",{{"Custom.1", type text}, {"Custom.2", Int64.Type}}), #"Added Custom1" = Table.AddColumn(#"Changed Type1", "Custom", each [Custom.1]&"."&Number.ToText([Custom.2])), #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Custom.1", "Custom.2"}) in #"Removed Columns"And you will see:
For the related .pbix file,pls see attached.
Best Regards,
KellyDid I answer your question? Mark my raeply as a solution!