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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.