Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
Not applicable

Execute the formula in a field

Hi All:

We have all the formulas in one table with sequence no in which it has to be executed. I tried and able to combine the smaller piece of formula into bigger one and made it available as part of data. Now i am not able to execue the formula.

I have also attached the sample app for your reference

Pls let me know if you have any answer.

Thanks in advance.

1 Solution

Accepted Solutions
msheraton
Contributor III

Re: Execute the formula in a field

The problem seems to be with the quotes.

For example

,EVALUATE(        IF(C1>C2, 999 ,IF(C1=C2,555,IF(C1=0,000)))  ) as Category2

will return values

I don't have time to play around and make this work but hopefully that's of some help.

6 Replies
Highlighted
Not applicable

Re: Execute the formula in a field

FYI..I need to execute at script level rather in expresession.

msheraton
Contributor III

Re: Execute the formula in a field

It was difficult following your script as you have not provided the data you are loading.

Anyway I had a go at it, basically just replacing the field names in the formula with the actual values. let me know if this helps...

// This just loads one row with "IF(C1>C2, 'Y',IF(C1=C2,'S',IF(C1=0,'N')))" in it.

TEMP:

LOAD Formula

FROM

(txt, codepage is 1252, embedded labels, delimiter is '\t', msq);

  

let vFormula = peek('Formula',0,'TEMP');

DROP TABLE TEMP;

TEMP:

LOAD * Inline [TY,C1,C2

A,2,1

B,1,1

C,1,1

D,0,2

];

COUNT:

LOAD COUNT(TY) AS X

Resident TEMP;

vRows = PEEK('X',0,'COUNT');

DROP TABLE COUNT;

for i=0 to vRows - 1

          let          vTY = PEEK('TY',$(i),'TEMP');

          let          vC1 = PEEK('C1',$(i),'TEMP');

          let          vC2 = PEEK('C2',$(i),'TEMP');

          let           vFormula_new  =Replace(vFormula,'C1','$(vC1)');

          let           vFormula_new2  =Replace(vFormula_new,'C2','$(vC2)');

          LET           vFormula_new3 = $(vFormula_new2);

 

          //          NoConcatenate I want it to concatnate so leave as it

          OUTPUT:

          LOAD * Inline [TY,vC1,vC2,Formula,Cat

          $(vTY),$(vC1),$(vC2)          ,$(vFormula),$(vFormula_new3)

          ];

next

DROP TABLE TEMP;

Not applicable

Re: Execute the formula in a field

Pls find the data for your reference. Meanwhile i will lookinto it.

msheraton
Contributor III

Re: Execute the formula in a field

The problem seems to be with the quotes.

For example

,EVALUATE(        IF(C1>C2, 999 ,IF(C1=C2,555,IF(C1=0,000)))  ) as Category2

will return values

I don't have time to play around and make this work but hopefully that's of some help.

Not applicable

Re: Execute the formula in a field

Thanks. I have resolved the issue.

Replaced my Evaluate function with your logics. It's working fine. Pls find the application and excel file for your reference.

msheraton
Contributor III

Re: Execute the formula in a field

Looks good, would you mark my post as correct or helpfull please.

Mark

Community Browser