Forum Discussion
Import SPSS file into Power BI
I can confirm this works for a Survey Monkey Result set! Thank you so much for this. A few things to keep in mind:
Make sure you're on the latest R Client to also have access to rxImport. I had to upgrade mine.
The last line assumes you have a column named weegvar. I suggest relaciing that with StartDate or RespondentId.
The questions don't have labels. so you will need to go back to your survey to figure out what q0011 really was about.
If you want to read multiple Survey Files in one hit it gets a bit more complicated. You need to use lapply to run rxImport mutlitple times. the issue is that you don't load the full dataset directly into memory but instead into an xdf file. Reloading the xdf file once you're done is all it then takes to use the data in Power BI.
Here is my version of the script to handle multiple surveys
#delete the xdf file so we don't duplicate data on each refresh.
tempFile <- "c:\\temp\\temp.xdf";
if (file.exists(tempFile))
{
file.remove(tempFile)
}
mySourceFiles <- list.files("d:\\yourpath", pattern = "*.sav", full.names=TRUE)
lapply(mySourceFiles, FUN = function(sav_file) {
rxImport(inData = sav_file, outFile=tempFile, append = file.exists(tempFile)) } )
ds<- rxImport(inData = tempFile)
has anyone overcome the issue where variable labels are not being imported into Power BI? I run the same script in R and variable labels come across but not in Power BI. The code I'm using is:
library(foreign)
dataset = read.spss("C:\\SPSS data files\\telephone2018.sav",use.value.labels =TRUE, to.data.frame =TRUE, full.names = TRUE )
Am I missing anything?
Any help much appreciated.
Thanks
Jo
- jamesperry7 years agoFrequent Visitor
I've used the Haven package as described https://rstudio-pubs-static.s3.amazonaws.com/466787_84982191b86e4591bfcee776e498a6d4.html
Worked perfectly.
James