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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
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
RedSky001
Partner - Creator III
Partner - Creator III

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.

View solution in original post

6 Replies
Not applicable
Author

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

RedSky001
Partner - Creator III
Partner - Creator III

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
Author

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

RedSky001
Partner - Creator III
Partner - Creator III

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
Author

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.

RedSky001
Partner - Creator III
Partner - Creator III

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

Mark