Variable counter for everytime excel writer writes

Hi,

I am working on a flow, where I use quite a lot of excel writers and I would like to use a variable counter to use for naming. So for example everytime an excel writer writes some data, the counter needs to update so 1,2,3 etc.

I am new to using loops and I can’t seem find the right nodes to use.

Additionally, how do I ensure that the counting sequence is the same across all executions? So an excel file called tax_1 isn’t suddenly called tax_3 on the next execution.

1 Like

Without knowing the structure of your workflow, its difficult to try to provide a solution. Do you have multiple Excel Writers in your workflow each of which you want to increment for each execution?

@LarryFisherman you could take a look at this article trying to give some insights and examples about loops.

You can use Flow Variables to make sure the execution within a loop is in the right order.

Hi rfeigel

Thanks for taking the time to reply. I have made a small flow to illustrate how the structure is. I have also found a solution to both the counting variable and execution order, but I don’t think this is a very elegant way of doing it.

Additionally, I would like to have the number as a part of a larger “naming string” for the sheet name, instead of having just the number as the sheet name. For example tax_subgroup_1, tax_subgroup_2.

Thanks, much appreciated!

Do you want a single workbook with multiple named sheets or multiple workbooks? This is a critical issue for developing a workflow. Could you share your workflow?

1 Like

Hi Larry,

I’ve uploaded a sample workflow addressing your question.

It’s built around an input table that determines:

  • How many files will be created
  • The target output folder
  • File base name

I used a recursive loop to generate the file names, followed by a Table Row to Variable and Case Switch structure to handle the rest of the logic.

And voilà!

You’ll find the screenshots and the KNIME flow attached. Hope it helps. Please feel free to ask your questions.

Best regards,

Alpay

Variable counter for everytime excel writer writes.knwf (45.5 KB)

3 Likes

Hi Alpay,

This very much seems like what I was looking for, thanks! I can’t for some reason open the attached knwf file, can it be shared in a different way?

1 Like

Hi Larry, thank you. I apologize for the inconvenience caused by the malfunctioning link.

Please check this link:

VariableFlow.knwf (43.8 KB)

Best,

Alpay