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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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