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
useless
New Member

R script

Please don't link to https://docs.microsoft.com/en-us/power-bi/connect-data/desktop-r-in-query-editor

 

I am just trying to get output matching the input.

I am using a .csv as a source as that webpage is saying.

I then add an R script as that webpage is saying.

 

I just want the table to come out as a table.

Right now, I have a table as excepted prior this step, and then after this step,

I have a different table, where one column is the variable name, and the other is the table nested within.

 

I want the table to look as it did (so in future I can actually do something with it in the script)

 

The script is:

output <- data.frame(dataset)

and I've tried variants like: output <- dataset, etc etc

 

What am I doing wrong that I can't get passed even this trivial step?

I honestly can't believe that I even need to post on a forum to find answer for this

 

1 ACCEPTED SOLUTION

Try clicking on the resulting Table in the Value column.

 

You could also select that cell at this step by appending "{0}[Value]".

#"Run R script" = R.Execute("output <- dataset",[dataset=Source]){0}[Value],

 

View solution in original post

4 REPLIES 4
AlexisOlson
Super User
Super User

Please share your M code from the Advanced Editor so that we can replicate what you're seeing.

Thanks for responding. I copied and pasted it below. I had to remove some stuff like file path and some column names etc just for privacy. I added screenshot of before / after the step.

 

 

let
    Source = Csv.Document(File.Contents("C:\Users\____\Documents\____\___Table.csv"),[Delimiter=",", Columns=34, Encoding=1252, QuoteStyle=QuoteStyle.None]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"", Int64.Type}, {"id", Int64.Type}, {"date", type date}, {"time", type text}, {"outcome_1", type text}, {"outcome_2", type text}, {"duration", type text}, {"file_name", type text}}),
    #"Run R script" = R.Execute("# 'dataset' holds the input data for this script#(lf)#(lf)output <- dataset",[dataset=Source]),
    #"Removed Columns" = Table.RemoveColumns(#"Run R script",{""}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"id", type text}})
in
    #"Changed Type1"

 

 

useless_0-1643511956827.png

 

useless_1-1643511983557.png

 

For context, my actual goal in the R script was to read a different .csv, run some logic, add some columns to the current table, then have it propagate into Power BI for visualisation, whilst also saving a truncated version to a third .csv.

I get how to do it in R, I just don't understand why the data is getting nested into a field before I do anything to it.

 

Try clicking on the resulting Table in the Value column.

 

You could also select that cell at this step by appending "{0}[Value]".

#"Run R script" = R.Execute("output <- dataset",[dataset=Source]){0}[Value],

 

Hi Alexis,

I think I figured out what had happened - and it's exactly as you suggested. I had deleted a step without realising it's importance.

 

After any Run R Script, there needs to be a follow up of equivalent:

 

= #"Run R script"{[Name="output"]}[Value]

 

as the next step to kind of navigate into the nested table or can use the code snippet you provided - mine is just the one auto-generated when I tried it again.

 

 

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