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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
mischelin11
Advocate I
Advocate I

R function set.seed() does not work in Power BI R script visual

 
Hi
 

I need to compute and visualize cluster analysis from R in Power BI desktop. I use set.seed()function to prevent clusters from changing over time. I run this code first in Power BI Desktop and next time i publish it and run it in Power BI services. And here is the problem, because in Power BI desktop it make different (different order) clusters then in Power BI services. Is it possible that the problem is in the set.seed function?

A part of R code is:

set.seed(123)
km.res <- kmeans(scale(costs_noout_of), 4, nstart = 25)
dd <- cbind(costs_noout_all , cluster = km.res$cluster)
grid.table(ddply(dd, .(cluster), nrow))

And result is a table where is only numbers of clusters and counts of observations in that clusters, which i need in the following calculations.

Can anyone helps me?

3 REPLIES 3
v-chuncz-msft
Community Support
Community Support

@mischelin11,

 

If convenient, please elaborate and share a more complete example for a quick test.

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.

 

 Hi @v-chuncz-msft,

 

I dont know, how to add more complete example for this issue.

I can only add two graphical results, first is from Power BI services and second is from Power BI Desktop. As you can see, these results are a little different.

 

Result from Power BI services:

Capture.PNG

 

Result from Power BI Desktop:

Capture2.PNG

 

 

@mischelin11,

 

This seems to be caused by sorting. Check if you could specify the sort order in R.

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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