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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
lbuzz
Frequent Visitor

Updating R query for all imported dataframe sets

Hello everyone,

It might be a straightforward answer but I am using 4 data frames as datasets which were generated in R code.

Now I am seeing a source icon on each of those datasets.

 

If I make changes to my R query, how do I ensure sure that each dataset uses the latest code? 

Do I need to copy paste the R code in all 4 locations so they pick up my new code? Is one enough and powerBI is smart to update for all?

In general, what is the best way to update a R query?

 

Many thanks.

3 REPLIES 3
mahoneypat
Microsoft Employee
Microsoft Employee

Please give an example of two of your queries (or mock example) to see how similar the updates are.  You could use query parameters and work them into your R code, so you only need to update it in one place.

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thank you very much for your response!
Actually there is only 1 R script - here is the beginning snippet - 

 

library("FinancialMath") #https://cran.r-project.org/web/packages/FinancialMath/FinancialMath.pdf
library("FinCal") #https://cran.r-project.org/web/packages/FinCal/FinCal.pdf
principal.amount <- 100000
number.of.periods <- 60
monthly.rate1<- 0.10/12
monthly.rate2<- 0.04/12


amortization.schedule1 <- amort.table(Loan = principal.amount,
n = number.of.periods,
i = monthly.rate1)
amortization.schedule1 <-data.frame(amortization.schedule1$Schedule)


present.value <- -pv(monthly.rate1, number.of.periods, pmt = amortization.schedule1$Payment[1])
amortization.schedule2 <- amort.table(Loan = present.value,
n = number.of.periods,
i = monthly.rate2)
amortization.schedule2 <-data.frame(amortization.schedule2$Schedule)

 

Now when I go to powerBI and run the script, I get the following popup and can import the dataframes by selecting them

lbuzz_0-1604929294017.png

 

After the import is successful, I see the gear icon for source on both of the data frames eg

lbuzz_1-1604929359149.png

This makes me feel that the data souce of both these tables is different, albeit they are generated from the same code. As I continue to build my script and import more data frames/tables, I'm confused on how do I ensure the consistency of code across all tables/frames? Do I have to change all sources one by one or can I somehow just 'update' the query once so that all tables pulled from that query are in sync?

mahoneypat
Microsoft Employee
Microsoft Employee

Maybe I'm unclear on what you are trying to do, but I would approach this as follows:

 

1.  Make a table with columns for present value, number of periods, and rate (maybe add an index column too to make filtering to single analysis on your report easier)

 

2.  Make function with your R script in it that takes those three values as inputs

 

3.  Add a column with Invoke Custom Function with your #2 function and then expand that table to get all your data appended together (which you could use slicers/filters/etc. to pull out what you need in visuals.

 

Alternatively, you could just use R in your visual and display the amortization schedule for whatever values are selected from slicers (What-If Parameters).  See this post I wrote on using the R visual like this.

https://powerpivotpro.com/2018/11/hijacking-the-r-visual/

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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