Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Save files by month and create new where no file exists

RBF
7 - Meteor

Hi all

 

I have data with records spanning multiple months.  The query which pulls the data is dynamic (current month plus 3 months back).  For example, if I were to run it today, it would pull all records relevant from 01 May through to the current date 9th August (it only pulls historical data, no forecast).

 

Dates are in this format in each record:

2023-08-08

 

After I run my transformations, I want to be able to save it in separate files by month. e.g. records for May data would be saved in a filed called Data-2023-05, records for June data would be saved in a file called Data-2023-06, etc

 

Where a file already exists, I want it to overwrite the file/data in the file.  

Where the file does not exist, I want it to create a new file for that month

 

How do I do that?

 

2 REPLIES 2
Felipe_Ribeir0
16 - Nebula

Hi @RBF 

 

Check the attached example, just adapt the filepath to your filepath inside of the formula tool. The secret is to build a filepath with the formula tool + configure the output tool to use this filepath.

 

filepath.png

 

TH
8 - Asteroid

This is actually default behaviour when using the Output Data tool.

If your output file is named "my_file.csv" and it doesn't exist then Alteryx will create it in the target location.

If a file with that name exists then Alteryx will overwrite it.

 

Now, you want to dynamically name the file depending on which months are in it.

The Output Data tool has a small checkbox near the bottom that says "Take File/Table Name From Field". If you use that then it will write out different files for every distinct value in the column. If you want everything in one file then just make sure that the field you specify in the tool only has the one date value. Creating that value in each row should be easily done with a FORMULA tool.

Labels