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

Preparing for a certification exam? Ask exam experts all your questions on May 15th. Register now.

Reply
Anonymous
Not applicable

Power BI R script CSV export

Hi,
Trying to run a Power BI desktop export to CSV using an R script.
 
Input data is a csv which i do some transformations on.
 
let
Source = Csv.Document(File.Contents("C:\Users\jacksparrow\Desktop\NewFiles\Qa-Data-Set-11---Abandoned-Applicants---Filled-2020-09-21.csv"),[Delimiter=",", Columns=12, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
#"Split Column by Delimiter" = Table.SplitColumn(#"Promoted Headers", "Job Status: FILLED Date", Splitter.SplitTextByDelimiter("T", QuoteStyle.Csv), {"Job Status: FILLED Date.1", "Job Status: FILLED Date.2"}),
#"Renamed Columns" = Table.RenameColumns(#"Split Column by Delimiter",{{"Job Status: FILLED Date.1", "Job Status: FILLED Date"}}),
#"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Job Status: FILLED Date", type date}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "DaysSinceFilled", each DateTime.LocalNow()),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"DaysSinceFilled", type date}}),
#"Renamed Columns1" = Table.RenameColumns(#"Changed Type1",{{"DaysSinceFilled", "Today"}}),
#"Added Custom1" = Table.AddColumn(#"Renamed Columns1", "Custom", each Duration.Days([Today]- [#"Job Status: FILLED Date"])),

THat is before the R script step.
 
Next i input the following for the R script :
 
write.csv('dataset',"C:\\Users\\jacksparrow\\Desktop\\test.csv" )
 
It then adds the above line for Pwer Query
 
#"Run R script" = R.Execute("write.csv('dataset',""C:\\Users\\jacksparrow\\Desktop\\test.csv"" )",[dataset=#"Added Custom1"])
in
#"Run R script"
 
But the output CSV it creates, is blank and has just these two lines


x
1 dataset

2 REPLIES 2
WendyXue
New Member

Just remove the single quotes, it should be dataset not 'dataset'. Also, replace \\ with /.

In query editor, click transform, click Run R script, then in the pop-up windown enter the code below:

write.csv(dataset,"C:/Users/jacksparrow/Desktop/test.csv")

lbendlin
Super User
Super User

What happens when you run your script in R Studio?

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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