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

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Make calculation based on a formula field

Hi, I'm a newbie in Talend, I will try to explain what I want to do.

I stock calculation formula based on value getting by ID. And I want in talend to make the calculation with the formula and values and stock the result in another table.

To show my tables :

The first table with a classic field Id and Value

0683p000009LzJL.png

 

And the second table with formula.

0683p000009Lz4A.png

 

My goal is to take each formula and do the math with the value of each ID in formula.
The first line of my formula's table : I want to make the calcul value of ID 001 (10) + value of ID 002 (26) = 36.
The second line : I want to make the calcul value of ID 001 (26) * value of ID 002 (52).
The last line : I want to make the calcul value of ID 001 (26) *19.5.

And I want to make the treatment for each line of formula's table and stock it in a third table.

Also the 2 tables and the formula's structure are not fixed for my work, so if you have another structure to make it possible I can take It.

Thanks if you can help me.

 

Cordially.

Labels (2)
13 Replies
fdenis
Master
Master

sorry the last line will be 1+2
Anonymous
Not applicable
Author

Hi Denis,

I've try but no, the last line will be ID001+ID002 because the first line will replace ID001, the second will replace ID002 and the third line will replace Id003 but not in the formula.

 

--> 1+ID002
--> ID001+2
--> ID001+ID002

 

Now i've a job that do what I want. But I want to optimize the replacement task.

 

So to detail, I've change the structure of formula's table to this structure :

 

0683p000009LzjV.png

And I make this job :

 

0683p000009Lzqp.png

The 1st part consist to set variable, and check the parameter we need to extract just what we need.

The 2nd part consist to replace each parameter in each formula, but I think we can make it more performant.

And the 3rd part I use the ScriptEngineManager to make the calculation and take the result.

So in the 2nd part I made this :

 

In the tMap, I've made a relation with filter that permit to make replacement only if we have the parameter.

0683p000009M04L.png

So the result is like :

PARAM_1{10}+PARAM_2{ID[002]}|100
PARAM_1{ID[001]}+PARAM_2{26}|100
PARAM_1{26}*PARAM_2{ID[003]}|101
PARAM_1{ID[002]}*PARAM_2{52}|101

 

Then I sort by ID to treat the result in tJavaRow.

 

In the tJavaRow, I take each line to replace each parameter I will take in each line for the same ID :

 

I used  global variables to stock the formula and the ID, and i make the replacement of the ID of the parameter with his value.

0683p000009M04Q.png

So I will have this kind of result :

PARAM_1{10}+PARAM_2{ID[002]}|100
PARAM_1{10}+PARAM_2{26}|100
PARAM_1{26}*PARAM_2{ID[003]}|101
PARAM_1{26}*PARAM_2{52}|101

 

Then I take the last row in the tAggregate, and delete with a regexp the "PARAM_*{" "}" part in the tReplace.

 

0683p000009LzjW.png

Then I made the calculation of each line with the result :

10+26|100 => 36|100

26*52|101 => 1352|101

 

Did someone have a better solution to replace each parameter in each formula ?

 

 

Thanks a lot fdenis and thanks everyone.

fdenis
Master
Master

on your tmap, you can keep variable from one row to the others.
set formula(row5) as main link. out1 as loockup (set match model to all matches)
Add a Var named formulaId at the end of Var.
store formulaId on the Var.FormulaId.

if you do so you can set Var.Out with:
if (row5.formulaId=Var.FormulaId) then Var.Out.Replave(…..)
else row1.Formula.Out.Replave(…..)

after you just have to get the last out group by formula.


the big question is: how many formula how many params and how many time?
Talend is an ETL.
there are some others software optimized to do that (have a look to R or mapR).
you can use Talend to call R.
good luck


fdenis
Master
Master

did you success on your task?