0

I have seen similar problems to this one but I have not found a solution for this specific case.

Context: I have some excel files imported into Power BI and I need to do some analysis.

Goal: I want to run the following code: head(my_df,3)

To achieve that I do the following: Home -> Transform Data -> Power Query Editor opens -> Click on "my_df" -> "Run R script" -> "output <- head(my_df,3)

This results in the following error message:

DataSource.Error: ADO.NET: R script error. Error in head(raw_booking, 3) : object 'raw_booking' not found Execution halted

Details: DataSourceKind=R DataSourcePath=R Message=R script error. Error in head(raw_booking, 3) : object 'raw_booking' not found Execution halted

I tried head(iris,3) and it worked!!! What am I missing?

James Z
  • 12,209
  • 10
  • 24
  • 44
Mig
  • 139
  • 2
  • 10

1 Answers1

1

"Run R script" takes the input data from the last applied step in the query and stores it as dataset in the script window.

Therefore, try:

output <- head(dataset, 3)
yhj
  • 26
  • 1
  • Wow it works! But how can I refer to other dataframes? For example, I have more than 1 data set, and I would like to take data from there to create a specific table. Is it possible? thanks! – Mig Jan 28 '21 at 14:28
  • 1
    Refer to this: https://stackoverflow.com/questions/44897796/operations-on-multiple-tables-datasets-with-edit-queries-and-r-in-power-bi – yhj Jan 28 '21 at 22:39