Chunk loop with CASE Switch

Hi,

image

As shown in the above image, I want each chunk (row) of a table to go through all the ports in CASE switch individually.
I believe I’m missing a variable node which can help me get this result, but not sure which one to use. I tried with Rule Engine Variable, but that did not work for me.

Thanks

Hey there,

do I understand correctly that the operations that follow each of the different output ports from the case switch start node should happen to each row in full? E.g.: First port goes to column expressions next to do something, second port goes to string manipulation to do something… every chunk should go through both operations?

If so:
Unsure if Case Switch is then the right approach - typically you want to use case switch to determine one option (therefore one path) that the input should go to next depending on a condition which you need to determine beforehand to tell the Case node which output port to use.

If all operations should apply to every chunk then why not just chain them one after the other inside the loop?

1 Like

Hi @MartinDDDD - Thanks for responding

Yes, I want each chunk to go through all the operations in that Case node. However, the operations are not entirely different.
Each operation is about shifting the date and joining to another table based on the shifted date and the match results should get added to the excel output one below the other.

Thanks for the additonal information.

Just to be really sure: Looking at the image, each chunk should first go through Date&TimeShift -5, then the following operations, after that it should go to the bottom date&time shift node -4 and go through all of those operations?

The case switch node is used to determine one port to send the input data to - I if my above understanding is correct than this shouldnt be needed in your use case.

Or are you saying that the order in which each row should go through the different operations may differ? i.e. some rows have to go through -4 first and then through -5?

1 Like

each chunk should first go through Date&TimeShift -5, then the following operations, after that it should go to the bottom date&time shift node -4 and go through all of those operations?

  • Yes

Or are you saying that the order in which each row should go through the different operations may differ? i.e. some rows have to go through -4 first and then through -5?

  • No

Hello @Asghar

If you want to go through each row you can do as follows

  1. InChunk Loop Start node prove Rows per Chunk as 1

1

  1. To carry out Switch case provide the flow variable as currentIteration to activate each port in sequence

I solved for demo example as follows

3

Regards,
Yogesh

Hi @yogesh_nawale - Thanks for your inputs

However, it is not working for me. I’m getting an error - Invalid output port specified

Can you share your workflow or dummy data so that we can identify where the error is…

Thanks

I think that there is no need for Switch Case here.

I also think the error you are getting when trying @yogesh_nawale suggestion is lets say your table as 20 rows and you have 10 output ports. Row 1 only goes to first port, row 2 to second etc.
once you hit iteration 11 it tries to send row 11 to output port 11which is a port that does not exist - you then get the error.

Might indeed be good to get a prototype example to better understand what you are trying to achieve.

2 Likes

@MartinDDDD /@yogesh_nawale

Here is the sample workflow
sample_1.knwf (29.5 KB)

1 Like

Hi @Asghar , in your sample workflow, you haven’t got any variable defined to control the case switch branch… so which branch are you expecting it to take for each iteration of the loop? (Currently it will always just choose the top branch).

I’ve been following this topic, and I am of a similar view to that expressed earlier by @MartinDDDD , that possibly the Case Switch is not the best approach for your problem.

Unfortunately I haven’t ascertained yet what problem you are trying to solve with it, as the discussion has been centred on making the case switch work, but it just “feels” like the case switch isn’t the right node for whatever it is you are wanting to do…

With your example workflow,

  • which branch do you want Row 1 to take?
  • which branch do you want Row 2 to take?
  • which branch do you want Row 3 to take?
    etc

If your answer to any of the above is “both branches” then the Case Switch is not for you! :wink:

Perhaps, if (based on your uploaded example flow) you could describe what your expected output should be, people can work out what the approach should be. At the moment, all that is happening is the approach is being dissected with no clear understanding of the goal. (A bit like helping somebody understand whether they are using the correct size of hammer to plaster a wall! :slight_smile: )

1 Like

hi @Asghar,

If you want to use ports of Case Switch node sequentially for each row,
eg, port 0 for Row0
port 1 for Row1
port 2 for Row2 and so on…

Make sure the following…

  1. In Chunk Loop Start provide Rows per Chunk as 1
  2. In Case Switch Start node, Flow Variable for Port Index/ Select active port is CurrentIteration
  3. The output ports in Case Switch node match the number of rows in input table (as Rows per Chunk = 1)so as to avoid your above mentioned error

Note that this is not a optimal solution as mentioned by all. It should be used when you have to perform different operations on each of the output nodes of Case Switch Start .

May be if you explain further what is the output you are expecting we can provide more optimal solution.

Regards,
Yogesh

1 Like

Hi @takbb - thank you for pitching in :slight_smile:

Yes, I do agree that I’ve not defined any variable to control the case switch. It is just I got confused as to which variable to use, so that I can get the results.

@yogesh_nawale - No, that is not how I want the workflow to process.
what I’m trying to do is -
port 0 for Row0
port 1 for Row0
port 2 for Row0 and so on…
again,
port 0 for Row1
port 1 for Row1
port 2 for Row1 and so on…

@MartinDDDD - here is an example as to how I want the output to be
assuming that date in column2_1 is added via Date Time Shift with 3 days before the date in column2 of Table 1

I’m trying to join the tables based on the date added via Date Time Shift and date in 2nd table.

here is the excel file, if you need the data
sample data.xlsx (10.2 KB)

hope this is helpful

Thank you,

2 Likes

I think I see what you want to achieve - and once you have added column3_main you then want to take column2 date again, shift it backwards by say 4 days and lookup a value in either the same or a different table and add another column to the same row.

I think you can do that all in one step:

And after that you can add another Date&Time Shift node, shift back by 4 days, add another joiner… Here’s the WF of what is in the image.
JoinExample.knwf (87.9 KB)

Edit: I chose left outer join in the Joiner just to show all the data - obviously you can make that a inner join to only keep those rows that match to avoid the missing values.

1 Like

Hello @Asghar,

This can be done using single loop without Case Switch node

sample_1.knwf (81.7 KB)
1

Note. The missing values in workflow are due to no matching values in Table 2

Thanks