Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
mike_honey
Memorable Member
Memorable Member

Auto-rename all Query columns e.g. to remove underscore

Today I was grappling with shaping a series of Queries based on a SQL Datawarehouse.  They use what's probably the best column naming standard (IMO) e.g. Sales_Amount.  However PBI Desktop doesnt seem to have any built-in way to change those in bulk - I wanted to replace underscores with space e.g. "Sales Amount".

 

After a bit of a wrestle I came up with a Query Step Function that will do just that:

 

Table.RenameColumns(#"Changed Type", Table.ToRows(Table.AddColumn(Table.FromList(Table.ColumnNames( #"Changed Type")), "New Column Name", each Text.Replace ( [Column1] , "_" , " " ))))

 

The easiest way to use this is to manually rename a single column - that will generate a "Rename Columns" step.  Then copy and paste that formula to replace the generated formula.  It assumes the prior Step was called "Changed Type", so edit that to suit. 

 

It is totally dynamic so it will adjust to any table or to any edits you make in prior steps.  You could extend it e.g. with Text.Proper to tidy up column names that are all upper or lower case.

25 REPLIES 25
greggyb
Resident Rockstar
Resident Rockstar

@arify, may I ask why you don't see any sort of intellisense coming soon? This is well out of my wheelhouse, but it seems like with the strong similarities to F#, a lot of the work will have already been done by th VS team.

 

Is it just low priority or am I missing something?

@greggyb, intellisense for M is definitely coming. It's got a slightly lower priority but we constantly talk about it. 

 

There's also an user voice thing for it:

https://ideas.powerbi.com/forums/265200-power-bi/suggestions/7202913-improve-the-advanced-query-edit...

 

 

 

greggyb
Resident Rockstar
Resident Rockstar

@pqian, thanks much. I don't get enough time to review the user voice ideas that much. I've added some votes to that item.

 

I'm actually still learning Power Query, but I like very much what I see. I'm still learning its performance characteristics and what good idioms are, but it's a fun process.

greggyb
Resident Rockstar
Resident Rockstar

Nice to see a programmatic solution to this. I would likely have done something with using headers as first row, transposing, doing a replace on the now-column of headers, re-transposing, and promoting to headers again.

 

Yours seems much more elegant.

Thats a nice solution! Personally I prefer using the UI rather than coding (for ease of understanding, debugging and maintenance).

 

But I tried it on a large-ish table (170,000 rows) and it stalled on the first Transpose.  I imagine at that point it has to load all the rows and generate 170,000 columns ...

 

So I'll probably stick with my method, unless it's guaranteed that there wont be too many rows.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.