cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sguenther
Advocate II
Advocate II

R Script not working as expected

Hi all,

 

I'm faced with the following problem:

I have a list of website pages, which I would like to group in different content groups based on regex matching. The only way to set this up in the Query Editor is via an R Script. This is how I set it up:

 

 

# 'dataset' holds the input data for this script
filter <- "(www\\.simscale\\.com\\/|www\\.simscale\\.com\\.googleweblight\\.com\\/)blog\\/(.*)"

# Define Functions
checkComp <- function(f) {grepl(f , as.character(dataset$"Initial Landing Page"), ignore.case=TRUE)}

returnComp <- function() {
	if (checkComp(filter)) {
		result <- "Blog"
	} else {
		result <- "Other"
	}
        return(result)
}

output <- within(dataset,{"Test"=returnComp()})

 

dataset$"Initial Landing Page" is the column that contains the page URL.

 

The problem is that the returnComp() function always returns "Other". I tried everything. Testing this function in an online R tester works as expected. Just in PowerBI it doesn't work. There seems to be an issue when I pass the column to the function. But I don't know what else to try.

 

The column containsthe URLs in plain text, like this: https://www.simscale.com/blog/2016/11/learn-finite-element-analysis-fea/

1 REPLY 1
v-chuncz-msft
Community Support
Community Support

@sguenther,

 

Add a custom function and invoke it for each row.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors