Forum Discussion

Tinus1905's avatar
Tinus1905
Resolver I
2 years ago
Solved

Export and email a table or report from PowerBi

I have a table in PowerBi with an R script for exporting on the local pc. Every week the table changed to the previous week. 

The R script exports a CSV on the local pc with the name of the week of the column in the table. 

Example: TEST 01-2024, TEST 02-2024 etc. 

 

# 'dataset' holds the input data for this script
week <- unique(dataset$Week) - 1
year <- format(Sys.time(), "%Y")
Table <- paste0("\\\\af01\\Users\\Tinus\\Desktop\\new\\TEST ", week, "-", year, ".csv")
write.table(dataset, file = Table, sep = ";", na = "", row.names = FALSE, quote = FALSE)

 

Email R script is no problem but how can I change the R script so that the attachment is the Export from the above R script. 

 

library(mailR)
send.mail(from = "[email protected]",
          to = "[email protected]",
          subject = "Test email subject",
          body = "Test emails body",
          smtp = list(host.name = "smtp.mailtrap.io", port = 25,
                      user.name = "********",
                      passwd = "******", ssl = TRUE),
          authenticate = TRUE,
          send = TRUE)

 

There are multible files in the folder so just add "attach.files" in the R script does not solve the problem. 

I also tried another solution, for example: Power Automate. But I cant found a solution that exports the file on the local pc. 

 

Many thanks. 

  • I find the solution. 

     

    script_files <- list.files(path = folder_path, pattern = "\\.csv$", full.names = TRUE)

3 Replies