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

Engine Works

Under the hood of Alteryx: tips, tricks and how-tos.
Wojtek_Dz
8 - Asteroid

I think that every Alteryx Designer user has met in their work the error message, “The process cannot access the file because it is being used by another process. (32).”

 

During my work, this error mostly appeared when I wanted to save a couple of different tabs in the same Excel file.

 

My example use case looks like this: we have a data set with columns like Full Name, Job Title, Department, etc. (as below) in one sheet in one Excel file.

 

image001.jpg

 

We would like to split this data set into separate tabs (by Job Title column) and save it as one Excel file.

 

We could use Control Containers, which are described here. But this option is available from the Alteryx Designer 2023.1 version. So, if you are using an older version of Alteryx Designer, I’m presenting my solutions below.

 

There are a couple of ways to solve this case:

 

  • Output tool configuration: 
    • Take File/Table Name From Field - this option is available to configure in Output Tool configuration. We are choosing by which column we would like to split the data set into separate tabs (in our case, it is Job Title)

 

image002.jpg

 

*optionally, before Output Tool, we can create a new column named Path with the Formula Tool, where we specify the path of the output file, and after “|||,” we put the column name by which we would like to split our results. In our case, the configuration should look like this:

 

image003.jpg

 

Then, we can use this Path as the Field Containing File Name or Part of File Name in Output Tool configuration.

 

  • The combination of Block Until Done, Append and Count tools + Output tool configuration as in the first solution.

 

image004.jpg

 

  • A Batch macro -  I’m using a list of Job Title as a control parameter for our macro, which I generate by aggregation--Group by Job Title column in the Summarize tool.

 image005.jpg

 

The inside of the macro looks like this:

 

image006.jpg

 

  • The Sys.sleep() function in the R tool

 

image007.jpg

 

The configuration of R tool looks like this:

 

image008.jpg

 

None of the above solutions reliably solved my problem with the error message: “The process cannot access the file because it is being used by another process. (32)”

 

But finally, I found a working solution which guarantees success for both Designer Desktop and Gallery workflows.

 

PowerShell solution

 

First, I created the new output file path which navigates the output tool to create Excel files with only one tab which contains only one type of Job Title.

 

image009.jpg

 

Second, I created *.bat file which allows Alteryx to run a PowerShell script.

 

image010.jpg

 

Third, I created script in PowerShell which reads all .xlsx files from dedicated directory (in my case all files with Grade* prefix) and then saves all sheets to one combined Excel file ALL_Sheets.xlsx.

 

image011.jpg

 

image012.jpg

 

Now, we go to the Event Mode configuration in our workflow. We choose the Run command.. option after expanding Add button.

 

image013.jpg

   

Then in Edit Event window, I set the configuration as below:

Run Event When: After Run Without Errors

Command: Path where you save *.bat file.

Timeout (in seconds): I expanded it to 1000s

 

At the end click “OK”

 

Cool, the first event is done.

 

image014.jpg

  

Next, I’m creating a second event by repeating the same steps as before.

 

image015.jpg

 

In this Edit Event window, I set up the configuration as below:

 

Run Event When: After Run Without Errors

Command: powershell

Command Arguments: rm Grade*.xlsx (this command remove all excel files with Grade* prefix)

Working Directory: Path to the folder where Alteryx saved all separated Excel files

Timeout (in seconds): I expanded it to 1000s

 

At the end, click “OK.”

 

image016.jpg

 

How does it work?

 

In the first step, Alteryx saves the Excel files with only one tab which contains only one type of Job Title. (in our case there is 33 new files.)

 

Then, the first event is on the way. It is start run the *.bat file which allows Alteryx to run the PowerShell file which combine all tabs from all *.xlsx files to one Excel file.

 

And in the end, the second event removes all Excel files with Grade* prefix.

 

Success! Now, we have one Excel file with split data by Job Title column.

 

Extra feature

 

Now, our use case is to save all the files created on the same date as one Excel file. We need to make a couple changes in our previous solution.

 

First, in the place where we are creating new path for output files, we append the date to our file name.

 

image017.jpg

 

Second, we need to add lines about the date to the PowerShell script like below.

 

image018.jpg

  

And that's all. Now, you can combine files created on the same day that the workflow was launched.

 

Comments
BS_THE_ANALYST
14 - Magnetar
14 - Magnetar

I'm confused why a batch macro wouldn't work in this instance? It will open and close a file per batch as it's iterative. I've not encountered this issue unless you're feeding multiple tabs through at once?

 

Have you read this blog by datanath before? https://community.alteryx.com/t5/Engine-Works/How-to-Render-to-Multiple-Named-Excel-Sheets/ba-p/1015... 

I'd highly recommend it as the reporting tools are rich for Excel outputs. Especially if you want conditional formatting upon output etc. The blog highlights not only how to create tabs per excel file but multiple files with multiple tabs on.

 

All the best,

BS

Wojtek_Dz
8 - Asteroid

Hi @BS_THE_ANALYST  yes you are right about batch macro. But in my project case  even if I implemented the batch macro solution this error still is showing up. That’s why I create this workaround ☺️

simonaubert_bd
13 - Pulsar

Hello @Wojtek_Dz 

Thanks for the tips and tricks but to be honest, it seems way too complicated. I proposed an idea with already 39 votes on it to make it simple
https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Ideas/Output-distinguish-between-Append-Pr...

 

Best regards,

Simon

Jsanders017
5 - Atom
 

If you choose 'change entire file path' in the output node (as long as you have entered the entire output path in the formula field) it will output the multiple tabs to the same spreadsheet with no errors.

 

Screenshot 2024-06-25 133604.pngScreenshot 2024-06-25 13364336.pngScreenshot 2024-06-25 1359033330.png