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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

How to prevent unwanted type conversion when data are passed to R transform

I am using an R transform to do conversion of several columns in my dataset. One of the columns that I do NOT want to transform is a text column of identifiers which are digits with leading zeros. However when this column arrives in the R environment, the data type is already "integer." Therefore when it comes back from the transform Power BI sees it as whole number, and doesn't preserve the leading zeros. It was hard to find a way to prevent this type conversion from character to numeric. If the column is already numeric when R gets it, there's no way to preserve the leading zeros. (And the number of digits and leading zeros in this column of identifiers can vary so it's hard to find a consistent way to use "paste" or "str_pad" in R to do the trick. )
 
I have found one workaround to prevent the text to numeric conversion, which is to add non-numeric content to the column before running the R transform. I use Transform-->Format-->Add prefix and put a "Z" in front of the digits (any non-digit would do), then after the R transform I remove the "Z" and this works. The data type of "character" is preserved.  Anybody have a more elegant technique to prevent the data type conversion?

 

I was also wondering if there is a way to pass to an R transform only SOME of the columns instead of the whole dataset. Is that an option?

 

 

0 REPLIES 0

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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