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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

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