Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
whenever I pull data from SSAS tables, they come as like this.
I want to bulk rename the colNames in a way that returns the value inside parenthesis
My end goal is this
I tried this. Is it the best-optimized way to do this, I want the best optimization possible for a large tbl.
CT = Table.TransformColumnTypes(
src,
{{"db[colA]", Int64.Type}, {"db[colB]", Int64.Type}, {"db[colC]", Int64.Type}}
),
Change = Table.TransformColumnNames(CT, each Text.Replace(Text.Split(_, "["){1}, "]", ""))
let
src=Table.FromRows(
Json.Document(
Binary.Decompress(
Binary.FromText("i45WMlTSUTICYmOlWJ1oJRMgyxSIzZRiYwE=", BinaryEncoding.Base64),
Compression.Deflate
)
),
let
_t = ((type nullable text) meta [Serialized.Text = true])
in
type table [#"db[colA]" = _t, #"db[colB]" = _t, #"db[colC]" = _t]
),
CT = Table.TransformColumnTypes(
src,
{{"db[colA]", Int64.Type}, {"db[colB]", Int64.Type}, {"db[colC]", Int64.Type}}
),
Change = Table.TransformColumnNames(CT, each Text.Replace(Text.Split(_, "["){1}, "]", ""))
in
Change
Thank you in advance.
Solved! Go to Solution.
I would try this way first, in a single rename columns step using List.Zip and List.Transform.
let
src=Table.FromRows(
Json.Document(
Binary.Decompress(
Binary.FromText("i45WMlTSUTICYmOlWJ1oJRMgyxSIzZRiYwE=", BinaryEncoding.Base64),
Compression.Deflate
)
),
let
_t = ((type nullable text) meta [Serialized.Text = true])
in
type table [#"db[colA]" = _t, #"db[colB]" = _t, #"db[colC]" = _t]
),
#"Renamed Columns" = Table.RenameColumns(src,List.Zip({Table.ColumnNames(src), List.Transform(Table.ColumnNames(src), each Text.BetweenDelimiters(_, "[", "]"))}))
in
#"Renamed Columns"
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
I have a custom function ShortenColumnNames that I run on all of these:
(Source as table) as table =>
let
ColNamesList = Table.ColumnNames(Source),
Transform = Table.RenameColumns(Source,
List.Transform(ColNamesList, each {_, Text.BetweenDelimiters(_, "[", "]")}))
in
Transform
So each of my SSAS queries starts like this (I keep the DAX queries separately):
let
Source = AnalysisServices.Database(Workspace, Dataset, [Query=DAXQuery, Implementation="2.0"]),
RenameCols = ShortenColumnNames(Source),
[...etc...]
Thanks @mahoneypat @AlexisOlson
I tested out each of our Query plan
Me, @AlexisOlson and @mahoneypat has exactly the same Query Plan as the following despite using different techniques. I don't know how?
I will use this
Table.TransformColumnNames(src, each Text.BetweenDelimiters(_, "[", "]"))
They actually generate the same list of lists, but I would go with the one from @AlexisOlson too. That approach is more elegant.
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
I have a custom function ShortenColumnNames that I run on all of these:
(Source as table) as table =>
let
ColNamesList = Table.ColumnNames(Source),
Transform = Table.RenameColumns(Source,
List.Transform(ColNamesList, each {_, Text.BetweenDelimiters(_, "[", "]")}))
in
Transform
So each of my SSAS queries starts like this (I keep the DAX queries separately):
let
Source = AnalysisServices.Database(Workspace, Dataset, [Query=DAXQuery, Implementation="2.0"]),
RenameCols = ShortenColumnNames(Source),
[...etc...]
I would try this way first, in a single rename columns step using List.Zip and List.Transform.
let
src=Table.FromRows(
Json.Document(
Binary.Decompress(
Binary.FromText("i45WMlTSUTICYmOlWJ1oJRMgyxSIzZRiYwE=", BinaryEncoding.Base64),
Compression.Deflate
)
),
let
_t = ((type nullable text) meta [Serialized.Text = true])
in
type table [#"db[colA]" = _t, #"db[colB]" = _t, #"db[colC]" = _t]
),
#"Renamed Columns" = Table.RenameColumns(src,List.Zip({Table.ColumnNames(src), List.Transform(Table.ColumnNames(src), each Text.BetweenDelimiters(_, "[", "]"))}))
in
#"Renamed Columns"
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
15 | |
10 | |
10 | |
8 | |
7 |