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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
BeardyGeorge
Advocate I
Advocate I

Prevent Power BI Automatically Renaming Columns to Include Spaces

Hi All,

 

I'm trying to make use of the R scripting option to make some visualisations, but it's presenting some fairly serious issues.

For starters, the fact Power BI replaces underscores in field names with spaces means that R has a very hard time actually doing any of the things it's been included for (ggplot2, for example, really doesn't like spaces, so "just use the full name" as suggested here won't cut it).

Is there any way of forcing Power BI to take field names exactly as they're written in source rather than trying to be "helpful" and add spaces?

Failing that, have people had much success with renaming columns (either using the plyr package or more manually) in Power BI?

Alternatively, is there a way of editing the "#create dataframe" section of an R script in Power BI? (so that I can manually define my column names).

Semi-relatedly, is there any plan to include the make.names function in the R dataset definition going forward?

 

Thanks,

 

George

1 ACCEPTED SOLUTION

On closer inspection it appears the spaces are automatically inserted at some point during the OLAP/MDX level rather than by PowerBI itself, however that doesn't really help resolve the problem.

Regardless of how the spaces are being inserted, I still need to get rid of them in R.

 

EDIT:

on testing it appears that the following solves the problem:

names(dataset) <- gsub(" ","_",names(dataset))

 

 

View solution in original post

2 REPLIES 2
Greg_Deckler
Community Champion
Community Champion

I am not seeing the underscores replaced by spaces. I imported from a CSV file and the columns came in with the underscores. Can you provide more details around source or exactly when/where you are seeing the underscores replaced?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

On closer inspection it appears the spaces are automatically inserted at some point during the OLAP/MDX level rather than by PowerBI itself, however that doesn't really help resolve the problem.

Regardless of how the spaces are being inserted, I still need to get rid of them in R.

 

EDIT:

on testing it appears that the following solves the problem:

names(dataset) <- gsub(" ","_",names(dataset))

 

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.