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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
sela
Partner - Contributor II
Partner - Contributor II

Evaluate calculation on script

 

Dear All

 

I have a few different formulas.
Every single formula needs to calculate different group on the same table.
For example, the formula for Group-1 is 'Sum(Fact1)' and the formula for Group-1 is 'Sum(Fact2)'

GroupFact1Fact2
Group-113
Group-113
Group-224
Group-224

 

There are an unknown number of groups and formulas.
I try to ' Evaluate' this calculation by using variables for each formula,
and call dynamically
to the related variable to the relevant group, but It didn’t worked:

SET vFormula_Group-1 = 'Sum(Fact1)';
SET vFormula_Group-2 = 'Sum(Fact2)';

LOAD
Group
,
Evaluate('vFormula_' & Group) AS Formula

 

I also try to 'Evaluate' by '$' sign:

$(vFormula_)

 

Is it possible?
Thanks for help,

Sela

 

1 Solution

Accepted Solutions
Not applicable

Hello Sela,

It is possible using variables with parameters.

Attaching sample app for you.

Code:

SET vFormula = "if($1 = 'Group-1', Sum(Fact1), if($1 = 'Group-2', Sum(Fact2)))";

LOAD

Group

,$(vFormula(Group)) AS Formula

Group By Group

;

LOAD * INLINE [

    Group, Fact1, Fact2

    Group-1, 1, 3

    Group-1, 1, 3

    Group-2, 2, 4

    Group-2, 2, 4

];

Result I received:

Screen Shot 08-01-16 at 10.33 PM.PNG

Hope it helps!

BR,

Kuba

View solution in original post

2 Replies
Not applicable

Hello Sela,

It is possible using variables with parameters.

Attaching sample app for you.

Code:

SET vFormula = "if($1 = 'Group-1', Sum(Fact1), if($1 = 'Group-2', Sum(Fact2)))";

LOAD

Group

,$(vFormula(Group)) AS Formula

Group By Group

;

LOAD * INLINE [

    Group, Fact1, Fact2

    Group-1, 1, 3

    Group-1, 1, 3

    Group-2, 2, 4

    Group-2, 2, 4

];

Result I received:

Screen Shot 08-01-16 at 10.33 PM.PNG

Hope it helps!

BR,

Kuba

sela
Partner - Contributor II
Partner - Contributor II
Author

Thank you Jakub,

Your solution solve my case perfectly!!!