<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: i want to create a mathematical formula in the context variable and use that formula in the job  can anyone help please in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/i-want-to-create-a-mathematical-formula-in-the-context-variable/m-p/2360151#M124806</link>
    <description>&lt;P&gt;OK, I have found a solution for you. It requires writing a Talend routine and using a third party library. There is a Java library found here (&lt;A href="http://mathparser.org/" target="_blank" rel="nofollow noopener noreferrer"&gt;http://mathparser.org/&lt;/A&gt;) which allows you to what you want. Download the appropriate Jar and add a Talend routine like below....&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;PRE&gt;package routines;

import org.mariuszgromada.math.mxparser.*;

public class Equations {

	public static Double runExpression(String expression, double a, double b, double c, double d, double f){
		
		Argument aVal = new Argument("a");
		Argument bVal = new Argument("b");
		Argument cVal = new Argument("c");
		Argument dVal = new Argument("d");
		Argument fVal = new Argument("f");
		
		aVal.setArgumentValue(a);
		bVal.setArgumentValue(b);
		cVal.setArgumentValue(c);
		dVal.setArgumentValue(d);
		fVal.setArgumentValue(f);
		
		//System.out.println(aVal.getArgumentName()+aVal.getArgumentValue());
		Expression ex = new Expression(expression, aVal, bVal, cVal, dVal, fVal);
		//System.out.println(ex.getExpressionString());
		//System.out.println(ex.getHelp());
		return ex.calculate();
		 
	}
}
&lt;/PRE&gt; 
&lt;P&gt;You will need to set up the routine Jar dependencies by right-clicking and select "Edit Routine Libraries".&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Once the above is done, you can supply your equations to a Context Variable and use that Context Variable at runtime with code similar to below...&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;PRE&gt;	double a = 5.0;
	double b = 2.0;
	double c = 3.0;
	double d = 4.0;
	double f = 2.0;
	
        context.myEquation = "(a*b*c)/d"; 
        System.out.println(routines.Equations.runExpression(context.myEquation",a,b,c,d,f));
        context.myEquation = "(a*b*c*f)/d";
	System.out.println(routines.Equations.runExpression(context.myEquation,a,b,c,d,f));&lt;/PRE&gt; 
&lt;P&gt;Note that I didn't use "e" in the equations above since "e" is a reserved value for the mXParser tool. You will have to bare that in mind when using this method.&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jun 2019 09:25:18 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2019-06-12T09:25:18Z</dc:date>
    <item>
      <title>i want to create a mathematical formula in the context variable and use that formula in the job  can anyone help please</title>
      <link>https://community.qlik.com/t5/Talend-Studio/i-want-to-create-a-mathematical-formula-in-the-context-variable/m-p/2360145#M124800</link>
      <description>&lt;P&gt;talend for data integration, i want to create a mathematical formula in the context variable and use that formula in the job can anyone help please?&lt;/P&gt;&lt;P&gt;say formula is a+b and I want to store it in the context variable (context.c=a+b)&lt;/P&gt;&lt;P&gt;and then I want to use it in tjavaRow&amp;nbsp; int c= context.c(it should do the addition of a and b)&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jun 2019 07:11:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/i-want-to-create-a-mathematical-formula-in-the-context-variable/m-p/2360145#M124800</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-06-10T07:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: i want to create a mathematical formula in the context variable and use that formula in the job  can anyone help please</title>
      <link>https://community.qlik.com/t5/Talend-Studio/i-want-to-create-a-mathematical-formula-in-the-context-variable/m-p/2360146#M124801</link>
      <description>&lt;P&gt;I'm afraid context variables are just variables. You cannot get them to act in this way. What is your use case? Maybe there is another way of achieving your requirement.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jun 2019 09:09:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/i-want-to-create-a-mathematical-formula-in-the-context-variable/m-p/2360146#M124801</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-06-10T09:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: i want to create a mathematical formula in the context variable and use that formula in the job  can anyone help please</title>
      <link>https://community.qlik.com/t5/Talend-Studio/i-want-to-create-a-mathematical-formula-in-the-context-variable/m-p/2360147#M124802</link>
      <description>&lt;P&gt;I need to take formula in context and I have to load formula from file to context since formula may change according to the requirement. In short I need to take formula from file to talend job(tMap or tJavaRow).&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jun 2019 09:28:31 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/i-want-to-create-a-mathematical-formula-in-the-context-variable/m-p/2360147#M124802</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-06-10T09:28:31Z</dc:date>
    </item>
    <item>
      <title>Re: i want to create a mathematical formula in the context variable and use that formula in the job  can anyone help please</title>
      <link>https://community.qlik.com/t5/Talend-Studio/i-want-to-create-a-mathematical-formula-in-the-context-variable/m-p/2360148#M124803</link>
      <description>&lt;P&gt;Can you give an example of the type of formula? Also, which product are you using? The Open Source Edition or the Enterprise Edition?&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jun 2019 12:56:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/i-want-to-create-a-mathematical-formula-in-the-context-variable/m-p/2360148#M124803</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-06-10T12:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: i want to create a mathematical formula in the context variable and use that formula in the job  can anyone help please</title>
      <link>https://community.qlik.com/t5/Talend-Studio/i-want-to-create-a-mathematical-formula-in-the-context-variable/m-p/2360149#M124804</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please use a tJava in Pre Job and write your formula.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;context.c = a+b;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then use context.c in the job and all child jobs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Subhadip&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2019 15:07:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/i-want-to-create-a-mathematical-formula-in-the-context-variable/m-p/2360149#M124804</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-06-11T15:07:37Z</dc:date>
    </item>
    <item>
      <title>Re: i want to create a mathematical formula in the context variable and use that formula in the job  can anyone help please</title>
      <link>https://community.qlik.com/t5/Talend-Studio/i-want-to-create-a-mathematical-formula-in-the-context-variable/m-p/2360150#M124805</link>
      <description>&lt;P&gt;I'm using talend open studio and formula some times (a*b*c)/d and some times (a*b*c*e)/d depends on the requirement. Can I get any solution to read the formula from file and execute the formula in talend job. Its going to be a great help...&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 05:46:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/i-want-to-create-a-mathematical-formula-in-the-context-variable/m-p/2360150#M124805</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-06-12T05:46:28Z</dc:date>
    </item>
    <item>
      <title>Re: i want to create a mathematical formula in the context variable and use that formula in the job  can anyone help please</title>
      <link>https://community.qlik.com/t5/Talend-Studio/i-want-to-create-a-mathematical-formula-in-the-context-variable/m-p/2360151#M124806</link>
      <description>&lt;P&gt;OK, I have found a solution for you. It requires writing a Talend routine and using a third party library. There is a Java library found here (&lt;A href="http://mathparser.org/" target="_blank" rel="nofollow noopener noreferrer"&gt;http://mathparser.org/&lt;/A&gt;) which allows you to what you want. Download the appropriate Jar and add a Talend routine like below....&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;PRE&gt;package routines;

import org.mariuszgromada.math.mxparser.*;

public class Equations {

	public static Double runExpression(String expression, double a, double b, double c, double d, double f){
		
		Argument aVal = new Argument("a");
		Argument bVal = new Argument("b");
		Argument cVal = new Argument("c");
		Argument dVal = new Argument("d");
		Argument fVal = new Argument("f");
		
		aVal.setArgumentValue(a);
		bVal.setArgumentValue(b);
		cVal.setArgumentValue(c);
		dVal.setArgumentValue(d);
		fVal.setArgumentValue(f);
		
		//System.out.println(aVal.getArgumentName()+aVal.getArgumentValue());
		Expression ex = new Expression(expression, aVal, bVal, cVal, dVal, fVal);
		//System.out.println(ex.getExpressionString());
		//System.out.println(ex.getHelp());
		return ex.calculate();
		 
	}
}
&lt;/PRE&gt; 
&lt;P&gt;You will need to set up the routine Jar dependencies by right-clicking and select "Edit Routine Libraries".&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Once the above is done, you can supply your equations to a Context Variable and use that Context Variable at runtime with code similar to below...&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;PRE&gt;	double a = 5.0;
	double b = 2.0;
	double c = 3.0;
	double d = 4.0;
	double f = 2.0;
	
        context.myEquation = "(a*b*c)/d"; 
        System.out.println(routines.Equations.runExpression(context.myEquation",a,b,c,d,f));
        context.myEquation = "(a*b*c*f)/d";
	System.out.println(routines.Equations.runExpression(context.myEquation,a,b,c,d,f));&lt;/PRE&gt; 
&lt;P&gt;Note that I didn't use "e" in the equations above since "e" is a reserved value for the mXParser tool. You will have to bare that in mind when using this method.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 09:25:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/i-want-to-create-a-mathematical-formula-in-the-context-variable/m-p/2360151#M124806</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-06-12T09:25:18Z</dc:date>
    </item>
  </channel>
</rss>

