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
webportal
Impactful Individual
Impactful Individual

Create table with R Script in Power Query

I'm using R package "cluster" in Power BI to cluster customers from their historical transactions.

 

My data looks like this:

enter image description here

Using Run R-Script command in Power Query Editor, I have the following code:

library(cluster)
k.means.fit_log <- kmeans(dataset[2:4], 3)
output<-dataset output$cluster <- k.means.fit_log$cluster

After this code is executed, I get an additional column with the number of the cluster and all looks good.

 

However, k.means.fit_log is a list with 9 rows, that contains the cluster centers, size, etc. so I'd like to be able to create another table or tables in Power BI with the contents of that object.

 

How can I achieve this?

 

Thanks in advance for your help!

1 ACCEPTED SOLUTION

@webportal ,

 

Just add the code above and use the latest version of Power BI Desktop.

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.

View solution in original post

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

@webportal ,

 

You may take a look at this post.

 

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.

@v-chuncz-msft sure I know only R dataframes can be used in Power BI.

 

I could add the following to my R code above:

 

x<- as.data.frame(k.means.fit_log$centers)

This returns a 3*3 dataframe.

 

The question is how to export this dataframe to a another table using Power Query?

@webportal ,

 

Just add the code above and use the latest version of Power BI Desktop.

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
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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
Top Kudoed Authors