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
Vmartin002
Frequent Visitor

R-Script Visual Runtime Error in Power BI Server

Hi Everyone, 

 

I wrote a R-Script that works/runs perfectly in Power BI Desktop but doesn't work when published to the Power BI Service. I'm not able to pinpoint the error, is it the pipe operator (%<%)? Any help would be highly apperciated, I've been struggling with this issue for some time now.  Script Runtime Error: Evaulation Error: Level sets of factors are different

 

Error_R.PNG

 

R-Script:

# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script:

# dataset <- data.frame(ProjectName, Commodity, WBS_code, Months, Running_Total_V2, Total_Scope_V2, RTPercentCompleteV2, Project_Description)
# dataset <- unique(dataset)

# Paste or type your script code here:
library(dplyr)
library(ggplot2)
library(RColorBrewer)


proposal_project <- unique(dataset[["Project_Description"]])

# there are duplicates due to WBS
df <- dataset %>% select(ProjectName, Commodity, Months, RTPercentCompleteV2) %>% distinct()

# for projects with multiple entries for the same percent complete, keep the highest value
df <- df %>% group_by(ProjectName, Commodity, RTPercentCompleteV2) %>% slice(which.max(Months)) %>% arrange(Months)

# group by and interpolate
pctcomplete <- seq(0.1, 1, by=0.05)
df <- df %>% group_by(ProjectName, Commodity) %>% group_modify(~ {approx(.x$RTPercentCompleteV2, .x$Months, xout=pctcomplete) %>% data.frame()}) %>% ungroup()
prop_df <- df %>% filter(ProjectName == proposal_project) # split out proposal data after transformations
df2df <- df %>% filter(ProjectName != proposal_project)


data_wo_proposal <- df2df %>% group_by(Commodity,x) %>% summarise_at(vars(y),list(mean_duration = mean))

# plot
mindiff <- min(c(0))
maxdiff <- max(c(max(data_wo_proposal$mean_duration, na.rm=TRUE), max(prop_df$y, na.rm=TRUE)))
ticks <- round(seq(mindiff, maxdiff, by=2))
tick_y <- seq(0,100, by=5)

g <- ggplot(data=data_wo_proposal, aes(x=mean_duration, y=x, colour=Commodity)) + geom_line(linetype=2) + geom_point()
final_plot <- g + geom_line(data = prop_df, aes(x=y,y=x,colour=Commodity)) + geom_point(data=prop_df,aes(x=y,y=x,colour=Commodity))
final_plot_label <-
final_plot + labs(title='Average Duration of Reference Projects vs Proposal Project', subtitle=paste('Proposal Project:',prop_df$ProjectName[1], '(solid line in figure below)'), x= 'Duration (Months)',y='Percent Complete') + theme_bw() + theme(legend.position='bottom', legend.title=element_blank()) + scale_colour_brewer(palette='Set1') + scale_x_continuous(breaks=ticks)+scale_y_continuous(labels = scales::percent_format(accuracy = 1),breaks=seq(0,1, by=.05))
final_plot_label

 

 

Thank you,

Val

1 ACCEPTED SOLUTION

Update:

 

I was able to figure out the issue with the R-Script Visual on the Power BI Service.

 

The level of factors was fixed by the following edits:

Orginal:
prop_df <- df %>% filter(ProjectName == proposal_project) 
df2df <- df %>% filter(ProjectName != proposal_project)
New:
prop_df <- df %>% filter(as.character(ProjectName)== as.character(proposal_project))
df2df <- df %>% filter(as.character(ProjectName) != as.character(proposal_project))
 
Also, make sure the package versions are up to date according to https://docs.microsoft.com/en-us/power-bi/connect-data/service-r-packages-support there happened to be unsupported function "group_modify" not supported by the approved dplyr package. Lastly, there seems to be some discrepancies with package versions. To ensure your R-script will run on the power BI service make sure your local machine is running Microsoft R 3.4.4 or R 3.4.4. This is the same R enviroment used on the cloud, so if it runs on your desktop with this version it will run on Power BI service. Also, use install.packages("_____") in your R-Terminal since this will allow package versions that are supported on R 3.4.4. this will help avoid ambiguity.
 
Best of luck!
Val

View solution in original post

2 REPLIES 2
winceeS
Frequent Visitor

Hi, R Visual is currently not supported in Power BI Report Server. it's only available in PBI Service.

checkout the  documentation.

https://docs.microsoft.com/en-us/power-bi/report-server/compare-report-server-service

Update:

 

I was able to figure out the issue with the R-Script Visual on the Power BI Service.

 

The level of factors was fixed by the following edits:

Orginal:
prop_df <- df %>% filter(ProjectName == proposal_project) 
df2df <- df %>% filter(ProjectName != proposal_project)
New:
prop_df <- df %>% filter(as.character(ProjectName)== as.character(proposal_project))
df2df <- df %>% filter(as.character(ProjectName) != as.character(proposal_project))
 
Also, make sure the package versions are up to date according to https://docs.microsoft.com/en-us/power-bi/connect-data/service-r-packages-support there happened to be unsupported function "group_modify" not supported by the approved dplyr package. Lastly, there seems to be some discrepancies with package versions. To ensure your R-script will run on the power BI service make sure your local machine is running Microsoft R 3.4.4 or R 3.4.4. This is the same R enviroment used on the cloud, so if it runs on your desktop with this version it will run on Power BI service. Also, use install.packages("_____") in your R-Terminal since this will allow package versions that are supported on R 3.4.4. this will help avoid ambiguity.
 
Best of luck!
Val

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.

Top Solution Authors