Generate counter/sequence upon certain value

Dear all,

I’m relatively new to KNIME and have a question about the following problem: I want to generate a sequence/number when a new group of data starts, which I can recognize by an empty line/cell.

A simplified example in below image. The first column represents my dataset. The second column represents what I want KNIME to generate. So KNIME should continue with an incremental number when a blank cell/row is reached and apply it to the next group of data.

image

I’m also open to other suggestions! But this was my initial idea.

Looking forward to suggestions!

1 Like

Hi @Sjoerd and welcome to the KNIME forum !
Please find here below a possible solution:

and the workflow:
20210721 Pikairos Generate counter sequence upon certain value.knwf (36.2 KB)

An easier solution is possible with just a Java snippet node based on Java programming.
Hints on how to solve it using Java can be found in the recent post Java snippets have long memories!... by @Takbb.

Hope this helps

Best

Ael

7 Likes

Hello @aworker,

you can modify expression in Rule Engine using ROWINDEX to drop Math Formula from workflow :wink:
$DATA$ = " " OR $$ROWINDEX$$ = 0 => 1

Br,
Ivan

6 Likes

Here’s another way to do it:

Input:
image

Result:
image

Workflow: Generate sequence upon certain value.knwf (31.0 KB)

5 Likes

Indeed @ipazin, nice trick :smile: :+1: !

Cheers

Ael

2 Likes

Come on @bruno29a, that doesn’t seem like a way to go :sweat_smile:
Ivan

@ipazin lol. I always miss using the Moving Aggregation node. I had built the workflow before you guys posted, but I’m on a slow computer, so opening paint, or saving the workflow is quite slow, and by the time I was ready to post, you guys had already replied. I figured, I’d still share it, just in case :slight_smile:

3 Likes

All fine :slight_smile:
Ivan
(Twenty characters)

Perfect, works like a charm! Thank you!

3 Likes

And only because @aworker would be disappointed if I didn’t join in :wink: … here is the java snippet:

I’ve borrowed @aworker’s Table Creator and the above snippet is included along with “yet another” workflow. Great to be able to showcase a variety of methods which demonstrate “fun uses” for different nodes.


Generate counter sequence upon certain value - more alternatives.knwf (27.4 KB)

This seems to be a popular problem! :slight_smile:

2 Likes

Haha ha @takbb, never disapointed with you lol ! And really glad you contributed with the Java Snippet solution and an alternative pure KNIME solution as well. All crystal clear as usual :wink: !

Thanks @takbb !

Best wishes to all of you,

Ael

4 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.