I want to count specific word in the row columns.

I have bwlow data set.
I want to use like countif in excel.
I want to count the “NG” each row and fill the number at Result column.
Result will be 2, 1, and 0.
I still beginner for the Knime. Please Help me.

Name A B C D Result
Andy NG OK OK NG
Ben OK OK OK NG
Cooper OK OK OK OK

Hi @clodnsky and welcome to the KNIME Forum!
Please see attached workflow on how to do this. You need to flatten your table first using a Create Collection Column followed by an Ungroup. Then you can use a GroupBy to count the combinations of name and NG/OK. After that you need to remove the OKs and join the result back with your original table using a right outer join, so that names where no NG occurred will have a missing value. Those missing values can then be replaced with 0 using a Missing Value node.
Kind regards
Alexander

Count_Column_Values.knwf (17.3 KB)

4 Likes

Nice!

Instead of adding a constant value column, we can first use the Row Filter to include only the NG values and then use the count aggregation on the value column in each “Name” group.

:blush:

3 Likes

Hi there @clodnsky,

additionally you can use Column Aggregator node with aggregation method Unique concatenate with count that will give you number of counts per each word. Then use String Manipulation or Column Expressions node to extract that number :wink:

Br,
Ivan

6 Likes

Super Nice! :wink:

:blush:

1 Like

This is the beauty of the tool and community, i like it.

Regards,
Pavan.

4 Likes

Here is another solution using only 1 node, the Column Expressions node.
Add this 5 lines of code in the node:

result = 0;
if (column(“A”).equals(“NG”)) result = result+1;
if (column(“B”).equals(“NG”)) result = result+1;
if (column(“C”).equals(“NG”)) result = result+1;
if (column(“D”).equals(“NG”)) result = result+1;

3 Likes

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