Reply
bml Frequent Visitor
Frequent Visitor
Posts: 7
Registered: ‎05-21-2018

R data column used for Slicer in Powerbi

Hi
is it possible to generate in a R visualisation above R a new Data colum, which is written to the dataset ( Grey box) and used Then as a PowerBi slicer?
How can it be present as a Slicer?
bests
Highlighted
Advisor
Posts: 348
Registered: ‎06-26-2015

Re: R data column used for Slicer in Powerbi

Not in the R visual. You could use R Script in the Power Query Editor though to add columns to the data model and then used in a slicer.

bml Frequent Visitor
Frequent Visitor
Posts: 7
Registered: ‎05-21-2018

Re: R data column used for Slicer in Powerbi

data(dataset)

head(dataset)
m <-dataset
nc <-ncol(dataset)
values <- dataset[,3:nc]
values
mean_is_0 <- sapply(values, mean) == 0
values <- values[ ! mean_is_0 ]
is.na(values) <- !values
values

mean_is_0 <- sapply(values, mean) == 0
values


for(i in 1:ncol(values)){
  values[is.na(values[,i]), i] <- mean(values[,i], na.rm = TRUE)
}  
values

test.pca <- prcomp(values,center = TRUE,scale. = TRUE)
plot(test.pca)
predict(test.pca,  newdata=tail(values, 2))
library(devtools)
library(ggbiplot)



sta5 <- test.pca$x[which(m$Obj == 5),]
   sta5[1:2]


sta4 <- test.pca$x[which(m$Obj == 4),]
sta4[1:2]
sta3 <- test.pca$x[which(m$Obj == 3),]
sta3[1:2]
sta2 <- test.pca$x[which(m$Obj == 2),]
sta2[1:2]
sta1 <- test.pca$x[which(m$Obj == 1),]
sta1[1:2]


g <- ggbiplot(test.pca, obs.scale = 1, var.scale = 1, ellipse = TRUE, 
              circle = FALSE) + geom_point(aes(x=sta5[1], y=sta5[2]), col="blue", size=4) + geom_point(aes(x=sta4[1], y=sta4[2]), col="blue", size=4)+ geom_point(aes(x=sta3[1], y=sta3[2]), col="blue", size=4)+ geom_point(aes(x=sta2[1], y=sta2[2]), col="blue", size=4)+ geom_point(aes(x=sta1[1], y=sta1[2]), col="blue", size=4) 


g <- g + scale_color_discrete(name = '')
g <- g + theme(legend.direction = 'horizontal', 
               legend.position = 'top')



print(g)

Hi 

i have following R code. Now I want introduce one new column "Belt". Can i do it directly in the RCode to add columns and use it as a slicer.

What comments I have to write?

My dataset is looking in this way and i want specify as new information Loc1 and Loc3 Belt1; Loc 2 and Loc4 Belt 2; Loc 5 and 6 Belt3.

 

Thanks for your help

 

Year    Obj Loc1    Loc2    Loc3    Loc4    Loc5    Loc6
17  1   1   5   1   2   1   4
17  2   2   4   3   4   3   3
17  3   3   3   5   3   2   2
17  4   4   2   2   2   4   5
17  5   5   1   4   1   5   1
Community Support Team
Posts: 1,375
Registered: ‎02-06-2018

Re: R data column used for Slicer in Powerbi

Hi bml,

 

To make R script use data in pbi data model, try pattern like below:

var <- dataset$column1
your code here
dataset$new_column <- var

Regards,

Jimmy Tao