Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Save $650 on Qlik Connect, Dec 1 - 7, our lowest price of the year. Register with code CYBERWEEK: Register
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to count number of similar strings in one row?

I have a file with hundreds of rows and about 60 columns looks like this

I want to count the number of Yes and No that exist in A PARTICULAR ROW.

 

id|A|B|C|.....

1|yes|yes|no|.....

2|no|yes|no|....

.

.

.

 

i want an output like this

 

id|numOfYes|numOfNo

1|2|1

2|1|2

.

.

.

 

how can i achieve that?

 

Thanks

Labels (2)
1 Reply
Anonymous
Not applicable
Author

Hi,

 

You can use this pattern 

0683p000009M9nK.png

1. Read each entire rows of your file,

2. In tmap split your id row and count the number of 'yes' and 'no'

out1.id = new Integer(row2.line.substring(0, row2.line.indexOf("|", 1)) ) // id

out1.numYes = StringHandling.COUNT(StringHandling.UPCASE(row2.line), "YES") // number of yes

out1.numNo = StringHandling.COUNT(StringHandling.UPCASE(row2.line), "NO")  // number of no

3. write your data using tfileoutputdelimited component