Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now
I am following this tutorial to incorporate R into Microsoft PowerBI, http://radacad.com/power-bi-and-regular-expressions
Using my own data
I understand how
# 'dataset' holds the input data for this script
pattern <- "[[:digit:]]{2}[[:alpha:]]{1}[[:digit:]]{3}"
isValid <- function(x) {grepl(pattern , as.character(x), ignore.case=TRUE)}
output <- within(dataset,{Building=isValid(dataset$GROUP_NAME)})
Translates to
But how do I print out the matching string itself, i.e. 02M477, 08X048, etc
I tried
# 'dataset' holds the input data for this script
pattern <- "[[:digit:]]{2}[[:alpha:]]{1}[[:digit:]]{3}"
isValid <- function(x) {grep(pattern , as.character(x), ignore.case=TRUE, value=TRUE)}
output <- within(dataset,{Building=isValid(dataset$GROUP_NAME)})
And I expect
Yet I get following error ... how to fix?
DataSource.Error: ADO.NET: R script error.
Error in `[<-.data.frame`(`*tmp*`, nl, value = list(Building = c("Madison\\Manual\\02M477-Shift Stick", :
replacement element 1 has 760 rows, need 768
Calls: within -> within.data.frame -> [<- -> [<-.data.frame
Execution halted
Details:
DataSourceKind=R
DataSourcePath=R
Message=R script error.
Error in `[<-.data.frame`(`*tmp*`, nl, value = list(Building = c("Madison\\Manual\\02M477-Shift Stick", :
replacement element 1 has 760 rows, need 768
Calls: within -> within.data.frame -> [<- -> [<-.data.frame
Execution halted
ErrorCode=-2147467259
ExceptionType=Microsoft.PowerBI.Scripting.R.Exceptions.RScriptRuntimeException
Hi @ArtieLadie ,
Could you please tell me if your problem has been solved? If it is, could you please mark the helpful replies as Answered to close this topic?
Regards,
Daniel He
Hi @ArtieLadie ,
Based on my test, maybe you could refer to below workaround:
Use the split function:
And ues this function again(with character):
You could also download the pbix file to have a view.
Regards,
Daniel He
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
Check out the February 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 61 | |
| 54 | |
| 38 | |
| 16 | |
| 15 |
| User | Count |
|---|---|
| 94 | |
| 85 | |
| 32 | |
| 31 | |
| 25 |