<?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: Does the IF-statement evaluate whole expression? in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Does-the-IF-statement-evaluate-whole-expression/m-p/1636592#M47422</link>
    <description>&lt;P&gt;I would do that, but I am using my measures in Text And Image objects and not KPI's, so it doesn't look like Calculation Condition is available.&lt;/P&gt;</description>
    <pubDate>Thu, 17 Oct 2019 10:23:24 GMT</pubDate>
    <dc:creator>NicolaiF</dc:creator>
    <dc:date>2019-10-17T10:23:24Z</dc:date>
    <item>
      <title>Does the IF-statement evaluate whole expression?</title>
      <link>https://community.qlik.com/t5/App-Development/Does-the-IF-statement-evaluate-whole-expression/m-p/1636561#M47418</link>
      <description>&lt;P&gt;Hi Qlik Community,&lt;/P&gt;&lt;P&gt;I am working with an app which is running slow - Thus, I am trying to optimize its performance.&lt;/P&gt;&lt;P&gt;I regognized that I could maybe condition some of my measures, so that if nothing is selected, the measure returns 0 by default and skipping the actual expression. However, It seems like the whole expression is evaluated regardless?&lt;/P&gt;&lt;P&gt;The example underneath shows the structure of my measure.&lt;/P&gt;&lt;P&gt;IF(GetSelectedCount(Field)=0, 0, [Expression])&lt;/P&gt;&lt;P&gt;I would expect that Qlik simply evaluates the condition (GetSelectedCount(Field)=0) and returns 0 and skipping the Expression.&lt;/P&gt;&lt;P&gt;However, when putting in a heavy expression my measure takes a long time to evaluate - even though GetSelectedCount(Field)&amp;nbsp; is equal to 0.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know how the IF-statement is eveluating its input?&lt;BR /&gt;Does anyone know a workaround to achieve what I am trying to do?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 04:21:31 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Does-the-IF-statement-evaluate-whole-expression/m-p/1636561#M47418</guid>
      <dc:creator>NicolaiF</dc:creator>
      <dc:date>2024-11-16T04:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: Does the IF-statement evaluate whole expression?</title>
      <link>https://community.qlik.com/t5/App-Development/Does-the-IF-statement-evaluate-whole-expression/m-p/1636566#M47419</link>
      <description>&lt;P&gt;it is better to use the calculation condition than in expression&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 09:42:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Does-the-IF-statement-evaluate-whole-expression/m-p/1636566#M47419</guid>
      <dc:creator>martinpohl</dc:creator>
      <dc:date>2019-10-17T09:42:40Z</dc:date>
    </item>
    <item>
      <title>Re: Does the IF-statement evaluate whole expression?</title>
      <link>https://community.qlik.com/t5/App-Development/Does-the-IF-statement-evaluate-whole-expression/m-p/1636592#M47422</link>
      <description>&lt;P&gt;I would do that, but I am using my measures in Text And Image objects and not KPI's, so it doesn't look like Calculation Condition is available.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 10:23:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Does-the-IF-statement-evaluate-whole-expression/m-p/1636592#M47422</guid>
      <dc:creator>NicolaiF</dc:creator>
      <dc:date>2019-10-17T10:23:24Z</dc:date>
    </item>
    <item>
      <title>Re: Does the IF-statement evaluate whole expression?</title>
      <link>https://community.qlik.com/t5/App-Development/Does-the-IF-statement-evaluate-whole-expression/m-p/1636633#M47426</link>
      <description>&lt;P&gt;Yes, an if-loop in Qlik evaluates always all branches. It's not an error else a design-decision - which has some benefits as well as disadvantages ...&lt;/P&gt;&lt;P&gt;Workarounds could be like already mentioned conditions for the expression or maybe the visibility of the objects - means you need at least two of them. Further you could also use a table-chart instead of the textbox - it doesn't need mandatory any dimension and with some layout-adjustment it looks like a textbox.&lt;/P&gt;&lt;P&gt;Another way to reduce the calculation-times might be to include the condition within the expression in a set analysis.&lt;/P&gt;&lt;P&gt;But I think in your case you might also replace the if-loop with something like this:&lt;/P&gt;&lt;P&gt;pick(sign(GetSelectedCount(Field)) + 1, 0, [Expression])&lt;/P&gt;&lt;P&gt;- Marcus&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 11:42:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Does-the-IF-statement-evaluate-whole-expression/m-p/1636633#M47426</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2019-10-17T11:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: Does the IF-statement evaluate whole expression?</title>
      <link>https://community.qlik.com/t5/App-Development/Does-the-IF-statement-evaluate-whole-expression/m-p/1636650#M47428</link>
      <description>&lt;P&gt;May be look here&amp;nbsp;&lt;A href="https://community.qlik.com/t5/QlikView-Scripting/help-performance-improvements/m-p/626750#558313" target="_self"&gt;https://community.qlik.com/t5/QlikView-Scripting/help-performance-improvements/m-p/626750#558313&lt;/A&gt;&lt;/P&gt;&lt;P&gt;An alternate would be to use Pick(Match())&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 12:01:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Does-the-IF-statement-evaluate-whole-expression/m-p/1636650#M47428</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2019-10-17T12:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: Does the IF-statement evaluate whole expression?</title>
      <link>https://community.qlik.com/t5/App-Development/Does-the-IF-statement-evaluate-whole-expression/m-p/1636701#M47432</link>
      <description>&lt;P&gt;I think&lt;BR /&gt;&lt;SPAN&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;pick(sign(GetSelectedCount(Field)) + 1, 0, [Expression])&amp;nbsp;&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;EM&gt;&lt;BR /&gt;&lt;/EM&gt;would solve the example I stated in the question.&amp;nbsp;&lt;BR /&gt;However, my actual measure contains several IF-statements.. I am not sure if your solution would be able to solve that as well?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My actual measure looks like the example below:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;IF(GetSelectedCount(Field1)=1, [Expression1]&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;IF(GetSelectedCount(Field2)=1, [Expression2]&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;IF(GetSelectedCount(Field3)=1, [Expression3],&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;[Expression4]&lt;/SPAN&gt;&lt;SPAN&gt;)))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Sorry for not claryfying that in the original question.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 13:02:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Does-the-IF-statement-evaluate-whole-expression/m-p/1636701#M47432</guid>
      <dc:creator>NicolaiF</dc:creator>
      <dc:date>2019-10-17T13:02:07Z</dc:date>
    </item>
    <item>
      <title>Re: Does the IF-statement evaluate whole expression?</title>
      <link>https://community.qlik.com/t5/App-Development/Does-the-IF-statement-evaluate-whole-expression/m-p/1636710#M47433</link>
      <description>&lt;P&gt;May be try like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Pick(
  Match(1
    , GetSelectedCount(Field1)
    , GetSelectedCount(Field2)
    , GetSelectedCount(Field3)
  ) + 1
, [Expression4]
, [Expression1]
, [Expression2]
, [Expression3])&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 17 Oct 2019 13:08:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Does-the-IF-statement-evaluate-whole-expression/m-p/1636710#M47433</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2019-10-17T13:08:20Z</dc:date>
    </item>
    <item>
      <title>Re: Does the IF-statement evaluate whole expression?</title>
      <link>https://community.qlik.com/t5/App-Development/Does-the-IF-statement-evaluate-whole-expression/m-p/1636732#M47434</link>
      <description>&lt;P&gt;It looks like this actually works.&lt;BR /&gt;However, as with the nested IF-functions, it still looks like it evaluates alle the expressions.&lt;BR /&gt;Also, it doesn't seem to improve performance enough to notice.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 13:45:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Does-the-IF-statement-evaluate-whole-expression/m-p/1636732#M47434</guid>
      <dc:creator>NicolaiF</dc:creator>
      <dc:date>2019-10-17T13:45:23Z</dc:date>
    </item>
    <item>
      <title>Re: Does the IF-statement evaluate whole expression?</title>
      <link>https://community.qlik.com/t5/App-Development/Does-the-IF-statement-evaluate-whole-expression/m-p/1636766#M47440</link>
      <description>&lt;P&gt;I think you could apply the same main-logic with something like:&lt;/P&gt;&lt;P&gt;pick(-rangemin(&lt;BR /&gt;(GetSelectedCount(Field1)=1)*3,&lt;BR /&gt;(GetSelectedCount(Field2)=1)*2,&lt;BR /&gt;(GetSelectedCount(Field3)=1)*1) + 1, 'exp4', 'exp3', 'exp2', 'exp1')&lt;/P&gt;&lt;P&gt;In general you need only a smart logic to control the pick-return and there are even more complex logic possible.&lt;/P&gt;&lt;P&gt;Beside this you could like above mentioned also use a table-chart - see here the last answer in the post to get an idea what's meant: &lt;A href="https://community.qlik.com/t5/QlikView-App-Development/bold-for-the-particular-text-in-the-text-box/td-p/1147456" target="_self"&gt;bold-for-the-particular-text-in-the-text-box&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;- Marcus&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 14:19:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Does-the-IF-statement-evaluate-whole-expression/m-p/1636766#M47440</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2019-10-17T14:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: Does the IF-statement evaluate whole expression?</title>
      <link>https://community.qlik.com/t5/App-Development/Does-the-IF-statement-evaluate-whole-expression/m-p/1636792#M47447</link>
      <description>&lt;P&gt;Like explained in the link which Sunny has provided behaves match() identically with if() in regard of evaluating at first all branches and checking the condition afterwards. I never tested it but I believe pick() behaved differently and just returned the n parameter - if I'm right you should notice it.&lt;/P&gt;&lt;P&gt;- Marcus&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 14:41:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Does-the-IF-statement-evaluate-whole-expression/m-p/1636792#M47447</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2019-10-17T14:41:09Z</dc:date>
    </item>
  </channel>
</rss>

