<?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: Read formula and calculate based on fields in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Read-formula-and-calculate-based-on-fields/m-p/2496858#M102702</link>
    <description>&lt;P&gt;It's not possible - it remains always a string. By selecting a single one the string could be interpreted into a formula with a $-sign expansion but I assume that's not expedient in your case. The only way to perform row/column-value-depening different calculations is the use of appropriate nested if-loops.&lt;/P&gt;</description>
    <pubDate>Mon, 09 Dec 2024 12:34:44 GMT</pubDate>
    <dc:creator>marcus_sommer</dc:creator>
    <dc:date>2024-12-09T12:34:44Z</dc:date>
    <item>
      <title>Read formula and calculate based on fields</title>
      <link>https://community.qlik.com/t5/App-Development/Read-formula-and-calculate-based-on-fields/m-p/2496776#M102696</link>
      <description>&lt;P&gt;Greetings.&lt;/P&gt;
&lt;P&gt;In the QlikSense script, I have a table with some fields and a formula descriptor that defines the formula to be used for output. Is there a way to interpret the text in formula as a field and get the appropriate result?&lt;/P&gt;
&lt;TABLE width="585"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;&lt;STRONG&gt;ID&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="283"&gt;&lt;STRONG&gt;FORMULA&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="75"&gt;&lt;STRONG&gt;UNIT_RATE&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="83"&gt;&lt;STRONG&gt;MTOW_TON&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="80"&gt;&lt;STRONG&gt;FIXED_RATE&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;UNIT_RATE * ROUNDUP((MTOW_TON * 2), 0)&lt;/TD&gt;
&lt;TD&gt;10&lt;/TD&gt;
&lt;TD&gt;50&lt;/TD&gt;
&lt;TD&gt;1000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;FIXED_CHARGES * 0.25&lt;/TD&gt;
&lt;TD&gt;20&lt;/TD&gt;
&lt;TD&gt;40&lt;/TD&gt;
&lt;TD&gt;2000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;MAX(UNIT_RATE * (MTOW_TON/1000), 100)&lt;/TD&gt;
&lt;TD&gt;50&lt;/TD&gt;
&lt;TD&gt;1000&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The expected outvalue value is shown in column EXPECTED_OUTPUT_VALUE below along with the calculation&lt;/P&gt;
&lt;TABLE width="923"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;ID&lt;/TD&gt;
&lt;TD width="283"&gt;FORMULA&lt;/TD&gt;
&lt;TD width="75"&gt;UNIT_RATE&lt;/TD&gt;
&lt;TD width="83"&gt;MTOW_TON&lt;/TD&gt;
&lt;TD width="80"&gt;FIXED_RATE&lt;/TD&gt;
&lt;TD width="168"&gt;&lt;FONT color="#FF6600"&gt;&lt;EM&gt;EXPECTED CALCULATION&lt;/EM&gt;&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="170"&gt;&lt;FONT color="#339966"&gt;&lt;STRONG&gt;EXPECTED OUTPUT VALUE&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;UNIT_RATE * ROUNDUP((MTOW_TON * 2), 0)&lt;/TD&gt;
&lt;TD&gt;10&lt;/TD&gt;
&lt;TD&gt;50&lt;/TD&gt;
&lt;TD&gt;1000&lt;/TD&gt;
&lt;TD&gt;10 * ROUNDUP((50 * 2), 0)&lt;/TD&gt;
&lt;TD&gt;1000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;TD&gt;FIXED_CHARGES * 0.25&lt;/TD&gt;
&lt;TD&gt;20&lt;/TD&gt;
&lt;TD&gt;40&lt;/TD&gt;
&lt;TD&gt;2000&lt;/TD&gt;
&lt;TD&gt;2000 * 0.25&lt;/TD&gt;
&lt;TD&gt;500&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;MAX(UNIT_RATE * (MTOW_TON/1000), 100)&lt;/TD&gt;
&lt;TD&gt;50&lt;/TD&gt;
&lt;TD&gt;1000&lt;/TD&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;MAX(50 * (1000/1000), 100)&lt;/TD&gt;
&lt;TD&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 08:58:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Read-formula-and-calculate-based-on-fields/m-p/2496776#M102696</guid>
      <dc:creator>sbfernandes</dc:creator>
      <dc:date>2024-12-09T08:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: Read formula and calculate based on fields</title>
      <link>https://community.qlik.com/t5/App-Development/Read-formula-and-calculate-based-on-fields/m-p/2496858#M102702</link>
      <description>&lt;P&gt;It's not possible - it remains always a string. By selecting a single one the string could be interpreted into a formula with a $-sign expansion but I assume that's not expedient in your case. The only way to perform row/column-value-depening different calculations is the use of appropriate nested if-loops.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 12:34:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Read-formula-and-calculate-based-on-fields/m-p/2496858#M102702</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2024-12-09T12:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: Read formula and calculate based on fields</title>
      <link>https://community.qlik.com/t5/App-Development/Read-formula-and-calculate-based-on-fields/m-p/2497764#M102778</link>
      <description>&lt;P&gt;Possible on the front-end, using combination of&amp;nbsp; functions Pick,Match and variables.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jpenuliar_0-1734026374483.png" style="width: 729px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/175665iD69AB914FC6F8C5F/image-dimensions/729x133?v=v2" width="729" height="133" role="button" title="jpenuliar_0-1734026374483.png" alt="jpenuliar_0-1734026374483.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;your formula has to be valid as qlik function&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;[Test]:&lt;BR /&gt;Load * Inline [&lt;BR /&gt;ID, FORMULA, UNIT_RATE, MTOW_TON, FIXED_RATE&lt;BR /&gt;formula1, "UNIT_RATE * ROUND(MTOW_TON * 2)", 10, 50, 1000&lt;BR /&gt;formula2, "FIXED_RATE * 0.25", 20, 40, 2000,&lt;BR /&gt;formula3, "RANGEMAX(UNIT_RATE * (MTOW_TON/1000), 100)", 50, 1000, 5&lt;BR /&gt;];&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;LET vNROWS = NoOfRows('Test');&lt;/P&gt;
&lt;P&gt;FOR i=0 to (vNROWS-1)&lt;BR /&gt;LET vVariable_Name = Peek('ID', i, 'Test');&lt;BR /&gt;[$(vVariable_Name)] = Peek('FORMULA', i, 'Test');&lt;/P&gt;
&lt;P&gt;next&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;chart expression:&amp;nbsp;Pick(Match(ID,'formula1','formula2','formula3')&lt;BR /&gt;, $(formula1)&lt;BR /&gt;, $(formula2)&lt;BR /&gt;, $(formula3)&lt;BR /&gt;)&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2024 18:02:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Read-formula-and-calculate-based-on-fields/m-p/2497764#M102778</guid>
      <dc:creator>jpenuliar</dc:creator>
      <dc:date>2024-12-12T18:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: Read formula and calculate based on fields</title>
      <link>https://community.qlik.com/t5/App-Development/Read-formula-and-calculate-based-on-fields/m-p/2497815#M102784</link>
      <description>&lt;P&gt;Logically it remains an if-loop - it simplifies only the handling.&lt;/P&gt;
&lt;P&gt;Be aware that there are reasons for not supporting this kind of measurements natively - mainly the serious disadvantages in regard to the performance.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2024 06:02:54 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Read-formula-and-calculate-based-on-fields/m-p/2497815#M102784</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2024-12-13T06:02:54Z</dc:date>
    </item>
    <item>
      <title>Re: Read formula and calculate based on fields</title>
      <link>https://community.qlik.com/t5/App-Development/Read-formula-and-calculate-based-on-fields/m-p/2497849#M102794</link>
      <description>&lt;P&gt;Hi! &lt;BR /&gt;To dynamically interpret the formula in the FORMULA field and calculate the expected output in Qlik Sense, you can use an Expression Evaluation approach. However, Qlik Sense scripting does not natively evaluate string-based expressions like a formula. Instead, you can preprocess the formula logic outside Qlik or use Qlik's scripting creatively to achieve the desired results.&lt;/P&gt;
&lt;P&gt;Qlik Sense scripting does not support direct evaluation of strings as formulas. To achieve this, we parse and map formulas to fields during the script load.&lt;/P&gt;
&lt;P&gt;Example Script:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;LOAD&lt;BR /&gt;ID,&lt;BR /&gt;FORMULA,&lt;BR /&gt;UNIT_RATE,&lt;BR /&gt;MTOW_TON,&lt;BR /&gt;FIXED_RATE,&lt;BR /&gt;IF(ID = 1, UNIT_RATE * CEIL(MTOW_TON * 2, 1), // Formula for ID 1&lt;BR /&gt;IF(ID = 2, FIXED_RATE * 0.25, // Formula for ID 2&lt;BR /&gt;IF(ID = 3, MAX(UNIT_RATE * (MTOW_TON / 1000), 100), NULL()))) AS EXPECTED_OUTPUT_VALUE&lt;BR /&gt;FROM [YourDataSource];&lt;BR /&gt;This method hardcodes the logic for each formula. While effective for small datasets, it’s not scalable.&lt;/P&gt;
&lt;P&gt;On other hand you can preprocess data in a more dynamic way using tools like Python or R to evaluate formulas dynamically before loading the results into Qlik Sense.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2024 09:42:43 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Read-formula-and-calculate-based-on-fields/m-p/2497849#M102794</guid>
      <dc:creator>diegozecchini</dc:creator>
      <dc:date>2024-12-13T09:42:43Z</dc:date>
    </item>
    <item>
      <title>Re: Read formula and calculate based on fields</title>
      <link>https://community.qlik.com/t5/App-Development/Read-formula-and-calculate-based-on-fields/m-p/2498001#M102831</link>
      <description>&lt;P&gt;Greetings.&lt;/P&gt;
&lt;P&gt;Thank you all for your suggestions and feedback. In this case I was able to solve the issue by using the &lt;STRONG&gt;Evaluate()&lt;/STRONG&gt; function in script.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This involves ensuring the functions can be interpreted by QlikSense and field names are present in the table.&lt;/P&gt;
&lt;P&gt;Eg: MAX as RangeMax, ROUNDUP as Ceil.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;=Evaluate(RANGEMAX(UNIT_RATE * (MTOW_TON/1000), 100))&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Dec 2024 04:23:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Read-formula-and-calculate-based-on-fields/m-p/2498001#M102831</guid>
      <dc:creator>sbfernandes</dc:creator>
      <dc:date>2024-12-15T04:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: Read formula and calculate based on fields</title>
      <link>https://community.qlik.com/t5/App-Development/Read-formula-and-calculate-based-on-fields/m-p/2498072#M102839</link>
      <description>&lt;P&gt;good idea thanks for sharing&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2024 07:27:16 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Read-formula-and-calculate-based-on-fields/m-p/2498072#M102839</guid>
      <dc:creator>diegozecchini</dc:creator>
      <dc:date>2024-12-16T07:27:16Z</dc:date>
    </item>
  </channel>
</rss>

