cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
bml Frequent Visitor
Frequent Visitor

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
3 REPLIES 3
deldersveld
Advisor

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

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
Highlighted
Community Support Team
Community Support Team

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

Helpful resources

Announcements
Back to School Contest

Back to School Contest

Engage and empower students with Power BI!

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Summit Australia 2019

Summit Australia 2019

Travel to Melbourne and network with thousands of peers!

PBI Community Highlights

PBI Community Highlights

Check out what's new in the Power BI Community!

Top Ideas
Users Online
Currently online: 185 members 1,988 guests
Please welcome our newest community members: