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: 
Pestaninha
Contributor III
Contributor III

Compare field value with string

Hi, I have the table bellow and I need to count values of 'String'  that are <= 'Plan'. Function SubtringCount Count(String,Plan) doesn't work because will only count the Match

Is this possible in script?

DocDoc ItStringPlanSubStringCount(String,Plan)Expected result
71610-10-12-14-15-15-16-17-17-7-7-8-8-8-8-8-8-9-9-97.0000000000000042
81710-10-12-14-15-15-16-17-17-7-7-8-8-8-8-8-8-9-9-97.0000000000000042
11010-10-12-14-15-15-16-17-17-7-7-8-8-8-8-8-8-9-9-98.0000000000000068
21110-10-12-14-15-15-16-17-17-7-7-8-8-8-8-8-8-9-9-98.0000000000000068
31210-10-12-14-15-15-16-17-17-7-7-8-8-8-8-8-8-9-9-98.0000000000000068
41310-10-12-14-15-15-16-17-17-7-7-8-8-8-8-8-8-9-9-98.0000000000000068
51410-10-12-14-15-15-16-17-17-7-7-8-8-8-8-8-8-9-9-98.0000000000000068
61510-10-12-14-15-15-16-17-17-7-7-8-8-8-8-8-8-9-9-98.0000000000000068
91810-10-12-14-15-15-16-17-17-7-7-8-8-8-8-8-8-9-9-99.00000000000000311
101910-10-12-14-15-15-16-17-17-7-7-8-8-8-8-8-8-9-9-99.00000000000000311
112010-10-12-14-15-15-16-17-17-7-7-8-8-8-8-8-8-9-9-99.00000000000000311
162510-10-12-14-15-15-16-17-17-7-7-8-8-8-8-8-8-9-9-910.00000000000000213
172610-10-12-14-15-15-16-17-17-7-7-8-8-8-8-8-8-9-9-910.00000000000000213
202910-10-12-14-15-15-16-17-17-7-7-8-8-8-8-8-8-9-9-912.00000000000000114
192810-10-12-14-15-15-16-17-17-7-7-8-8-8-8-8-8-9-9-914.00000000000000115
142310-10-12-14-15-15-16-17-17-7-7-8-8-8-8-8-8-9-9-915.00000000000000217
152410-10-12-14-15-15-16-17-17-7-7-8-8-8-8-8-8-9-9-915.00000000000000217
182710-10-12-14-15-15-16-17-17-7-7-8-8-8-8-8-8-9-9-916.00000000000000118
122110-10-12-14-15-15-16-17-17-7-7-8-8-8-8-8-8-9-9-917.00000000000000220
132210-10-12-14-15-15-16-17-17-7-7-8-8-8-8-8-8-9-9-917.00000000000000220

 

 

16 Replies
Pestaninha
Contributor III
Contributor III
Author

Many Thanks Kush, but the scripts stops before the execution of the final table and nothing happens

Kushal_Chawda

@Pestaninha  Not sure but if you can share your script I can help where is the issue. 

Pestaninha
Contributor III
Contributor III
Author

Thanks, but I don't think is feasible, as i have  a table with nearly 9600 records and length of string can achieve 50000 , so i think it gets stuck because is a lot of information to compare . Really appreciate your help though

Pestaninha
Contributor III
Contributor III
Author

Thanks Edwin, but still gives an error  'Out of memory' when running the script, I suppose is because is a lot of data to compare

Kushal_Chawda

@Pestaninha  length of the string doesn't matter .. there must be you are missing something. You can share screenshot of your script .

Kushal_Chawda

@Pestaninha  Try below. I removed if condition from formula

let vFormula1 =null();
let vFormula2 =null();
let vString_Field_Name = 'String'; // define name of the field which holds String value
let vCompare_Field_with_String ='Plan'; // define field name which you need to compare with String

Data:
LOAD Doc, 
     [Doc It], 
     SubStringCount(String,'-')+1 as Count,
     String, 
     Plan
FROM
[https://community.qlik.com/t5/New-to-QlikView/Compare-field-value-with-string/td-p/1767283]
(html, utf8, UserAgent is 'Mozilla/5.0', embedded labels, table is @1);

Max_Count:
LOAD max(Count) as Max_Count;
LOAD FieldValue('Count',RecNo()) as Count
AutoGenerate FieldValueCount('Count');

let vMax_Count = Peek('Max_Count',0,'Max_Count');

DROP Table Max_Count;

for i=1 to $(vMax_Count)

let vFormula1 = 'rangesum(';

let vFormula2 = '$(vFormula2)' & 'subfield($(vString_Field_Name),'&chr(39)&'-'&chr(39)&',$(i))<=$(vCompare_Field_with_String),';

NEXT 

let vFormula = '$(vFormula1)' & mid('$(vFormula2)',1,len('$(vFormula2)')-1) & ') *-1';

Final:
LOAD *,
     $(vFormula) as Results
Resident Data;

DROP Table Data;

let vFormula = null();
let vFormula1 = null();
let vFormula2 = null();
Pestaninha
Contributor III
Contributor III
Author

Wow it worked. I've tried for a shorter period and it worked, less lines and it worked.

Fantastic! Really happy. Thanks again have a good day