Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
bml
Regular 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

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.

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

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors