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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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