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
dramesh18
Frequent Visitor

R script as data source in Power BI Desktop

Hi All 
I am getting Data currently from different sources in flat files and I have to perform calculations to the data and have the transformed data stored in R dataframe, 
Is there any way to directly get the R dataframe which involves around 500+ lines of code calculations into powerBI from R.
Currently I have to split the Dataframe based on category and get two data sources in PowerBI based on Dashboard requirements.
Any help regarding will be appreciated.
Thanks 

1 ACCEPTED SOLUTION

OK, and this might very well be my misunderstanding of R but the way that I have worked with R dataframes in the past (limited) is that I have R code that reads some source and then I compose it into a dataframe within the R code, so something like:

 

N <- 100
u <- rnorm(N)
x1 <- rnorm(N)
x2 <- rnorm(N)
y <- 1 + x1 + x2 + u
mydat <- data.frame(y,x1,x2)

I guess what I was suggesting is that you put the code that creates/updates your data frame into the query as an R query or R query step. Are you saying that you have the R dataframe saved to a file as if you did something like this?

 

save(foo,file="data.Rda")

If that is the case, couldn't you do something like:

 

load("data.Rda")

In the first line of your R query or R query step?

 

 

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

You can create an R Script query as well as insert an R Script step into an existing query.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi smoupre Thanks for the review 
My issue is I have the data in my R dataframe I am trying to source it to powerBI and enable the refresh on weekly basis when I execute and update my R dataframe /code weekly.
I am unable to source the R script which only involves the split part for the dataframe,
the error I get is Datasource not found in this case the Dataframe not found,
I have set the working directory as well.
Thanks 

OK, and this might very well be my misunderstanding of R but the way that I have worked with R dataframes in the past (limited) is that I have R code that reads some source and then I compose it into a dataframe within the R code, so something like:

 

N <- 100
u <- rnorm(N)
x1 <- rnorm(N)
x2 <- rnorm(N)
y <- 1 + x1 + x2 + u
mydat <- data.frame(y,x1,x2)

I guess what I was suggesting is that you put the code that creates/updates your data frame into the query as an R query or R query step. Are you saying that you have the R dataframe saved to a file as if you did something like this?

 

save(foo,file="data.Rda")

If that is the case, couldn't you do something like:

 

load("data.Rda")

In the first line of your R query or R query step?

 

 

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi,
I have another query regarding the Data Update in PowerBI,
As I saved the Data in .Rda file how can I update the same table in PowerBI,
I can update the .Rda file from R but again I have to change the source in the Settings Tab for the PowerBI.

Awesome I dint even think of it..!!
Thanks alot I really appreciate 

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.