Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
P_Kale
Creator II
Creator II

How to extract desired word from quoted sentence

Hi,

In my data I am having 1 column where text is in quoted form. Eg. is given below.

1) [{"choice":"agreed","screen":"personal_details"},{"choice":"agreed","screen":"policy_details"},{"choice":"agreed","screen":"terms_and_conditions1"}]  = score is "1"

2) [{"choice":"Not_Agreed","screen":"personal_details"},{"choice":"agreed","screen":"policy_details"},{"choice":"agreed","screen":"terms_and_conditions1"}]  = score is "0"

my ask is if in a sentence after choice "agreed" word is there 3 times then in new column I should get score as "1"  and if after choice "Not_Agreed" found any where then I should get score as "0"

Can you pl help how i can achieve this.

Thanks in advance

Labels (1)
3 Replies
Parthiban
Creator
Creator

Try this,

if(WildMatch(fieldname,'*"agreed"*'),1,if(WildMatch(fieldname,'*"Not_Agreed"*'),0)).

jpenuliar
Partner - Specialist III
Partner - Specialist III

if you want to build it like a truth table :
you can make use of TextBetween and Subfield functions to break down the values.

jpenuliar_0-1702297951203.png

you can then substitute "agreed" , "not_agreed" values to logic 1 and 0 to get your answer.

barnabyd
Partner - Creator III
Partner - Creator III

G'day @P_Kale,

This problem is much simpler than you think. You said that 3 x "agreed" should give a result of '1'. I noticed that there are only three choices in each string, so that means that if any of them is any other value then the result should be '0'. So my solution is:

if( index( lower( fieldname ), '"agreed"', 3 ) > 0, 1, 0 )

This searches for the beginning of the 3rd occurrence and only succeeds if that is found. Every other possibility comes back as 0.

I hope this helps.

Cheers, Barnaby.

Barnaby Dunn
BI Consultant