Forum Discussion

Tinus1905's avatar
Tinus1905
Resolver I
2 years ago
Solved

PowerBI query export table using R script

Hi,   I have a table and whant to export this to CSV on a local computer.  This R script runs every week so on the local computer I whant the output name as: 48-2023, 49-2023 and so on.  In my ta...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Tinus1905 ,

     

    Please try:

    # 'dataset' holds the input data for this script
    
    # Get the current date and time
    now <- Sys.time()
    
    # Format the date to get the ISO week number and year
    week <- strftime(now, "%V-%Y")
    
    # Create the file path with the new naming convention
    Table <- paste0("\\\\af01\\Users\\Tinus\\Desktop\\new\\TEST", week, ".csv")
    
    # Write the dataset to the file
    write.table(dataset, file = Table, sep = ";", na = "", row.names = FALSE, quote = FALSE)
    ```

    Please note that %V gives you the ISO week number, and %Y gives you the year. Make sure that your system's locale settings support the %V format specifier for week number. If not, you may need to use an alternative method to calculate the week number. After making these changes, your script should export the table to a CSV file with the naming convention you desire (e.g., "TEST48-2023.csv").

     

    Best Regards,

    Neeko Tang

    If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

  • Tinus1905's avatar
    Tinus1905
    2 years ago

    Anonymous this is perfect. 

    Is it also possible in the R script to send the export as an attachement directly with email?