<?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 Separating Chart Expression into Smaller Functions in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Separating-Chart-Expression-into-Smaller-Functions/m-p/1771712#M59729</link>
    <description>&lt;P&gt;I have an expression for a measure in a chart that is working properly; however, it is becoming lengthy and a little difficult to follow its logic on first glance:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if(sum(drug_overdose) + 0*sum({1&amp;lt;year_incidence={$(=concat(distinct year_incidence,','))}&amp;gt;} drug_overdose)=0, 0,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(if((sum(drug_overdose) + 0*sum({1&amp;lt;year_incidence={$(=concat(distinct year_incidence,','))}&amp;gt;} drug_overdose))&amp;lt;5,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; '*',&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sum(drug_overdose) + 0*sum({1&amp;lt;year_incidence={$(=concat(distinct year_incidence,','))}&amp;gt;} drug_overdose))&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;)&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code "&lt;EM&gt;sum(drug_overdose) + 0*sum({1&amp;lt;year_incidence={$(=concat(distinct year_incidence,','))}&amp;gt;} drug_overdose)&lt;/EM&gt;" appears three times in my expression. Is it possible to break up the code in to something like the following?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FUNCTION=sum(drug_overdose) + 0*sum({1&amp;lt;year_incidence={$(=concat(distinct year_incidence,','))}&amp;gt;} drug_overdose)&lt;/P&gt;&lt;P&gt;if(FUNCTION=0, 0,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(if((FUNCTION)&amp;lt;5,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; '*',&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FUNCTION)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;)&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 16 Nov 2024 17:39:16 GMT</pubDate>
    <dc:creator>jashinskyjm</dc:creator>
    <dc:date>2024-11-16T17:39:16Z</dc:date>
    <item>
      <title>Separating Chart Expression into Smaller Functions</title>
      <link>https://community.qlik.com/t5/App-Development/Separating-Chart-Expression-into-Smaller-Functions/m-p/1771712#M59729</link>
      <description>&lt;P&gt;I have an expression for a measure in a chart that is working properly; however, it is becoming lengthy and a little difficult to follow its logic on first glance:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if(sum(drug_overdose) + 0*sum({1&amp;lt;year_incidence={$(=concat(distinct year_incidence,','))}&amp;gt;} drug_overdose)=0, 0,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(if((sum(drug_overdose) + 0*sum({1&amp;lt;year_incidence={$(=concat(distinct year_incidence,','))}&amp;gt;} drug_overdose))&amp;lt;5,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; '*',&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sum(drug_overdose) + 0*sum({1&amp;lt;year_incidence={$(=concat(distinct year_incidence,','))}&amp;gt;} drug_overdose))&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;)&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code "&lt;EM&gt;sum(drug_overdose) + 0*sum({1&amp;lt;year_incidence={$(=concat(distinct year_incidence,','))}&amp;gt;} drug_overdose)&lt;/EM&gt;" appears three times in my expression. Is it possible to break up the code in to something like the following?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FUNCTION=sum(drug_overdose) + 0*sum({1&amp;lt;year_incidence={$(=concat(distinct year_incidence,','))}&amp;gt;} drug_overdose)&lt;/P&gt;&lt;P&gt;if(FUNCTION=0, 0,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;(if((FUNCTION)&amp;lt;5,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; '*',&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FUNCTION)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;)&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 17:39:16 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Separating-Chart-Expression-into-Smaller-Functions/m-p/1771712#M59729</guid>
      <dc:creator>jashinskyjm</dc:creator>
      <dc:date>2024-11-16T17:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: Separating Chart Expression into Smaller Functions</title>
      <link>https://community.qlik.com/t5/App-Development/Separating-Chart-Expression-into-Smaller-Functions/m-p/1771719#M59730</link>
      <description>&lt;P&gt;Off course, You can create as variable and call that into measure like in script or simply from Variable overview&amp;nbsp;&lt;/P&gt;&lt;P&gt;Script:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;LET&amp;nbsp;FUNCTION='=sum(drug_overdose) + 0*sum({1&amp;lt;year_incidence={$(=concat(distinct year_incidence,','))}&amp;gt;} drug_overdose)';&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;OR&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Variable Overview:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;sum(drug_overdose) + 0*sum({1&amp;lt;year_incidence={$(=concat(distinct year_incidence,','))}&amp;gt;} drug_overdose)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And then your expression should be&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if($(FUNCTION)=0, 0,&amp;nbsp;(if($(FUNCTION)&amp;lt;5,&amp;nbsp;'*', $(FUNCTION))))&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jan 2021 18:20:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Separating-Chart-Expression-into-Smaller-Functions/m-p/1771719#M59730</guid>
      <dc:creator>Anil_Babu_Samineni</dc:creator>
      <dc:date>2021-01-04T18:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: Separating Chart Expression into Smaller Functions</title>
      <link>https://community.qlik.com/t5/App-Development/Separating-Chart-Expression-into-Smaller-Functions/m-p/1771730#M59731</link>
      <description>&lt;P&gt;Thank you for responding so quickly.&lt;/P&gt;&lt;P&gt;When I implemented the code you gave for the variable viewer, the chart displays the some of all counts across all time periods in each quarter. The original code breaks down the counts by each quarter. I included some example results below to illustrate:&lt;/P&gt;&lt;P&gt;Original code outputs:&lt;/P&gt;&lt;P&gt;Q1 = 125&lt;/P&gt;&lt;P&gt;Q2 = 150&lt;/P&gt;&lt;P&gt;Q3 = 100&lt;/P&gt;&lt;P&gt;Q4=200&lt;/P&gt;&lt;P&gt;New Code outputs:&lt;/P&gt;&lt;P&gt;Q1 = 575&lt;/P&gt;&lt;P&gt;Q2 = 575&lt;/P&gt;&lt;P&gt;Q3 = 575&lt;/P&gt;&lt;P&gt;Q4 = 575&lt;/P&gt;&lt;P&gt;Also, if it's put in the load script or the variable viewer, is it still able to adapt to selections that are made?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jan 2021 18:43:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Separating-Chart-Expression-into-Smaller-Functions/m-p/1771730#M59731</guid>
      <dc:creator>jashinskyjm</dc:creator>
      <dc:date>2021-01-04T18:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: Separating Chart Expression into Smaller Functions</title>
      <link>https://community.qlik.com/t5/App-Development/Separating-Chart-Expression-into-Smaller-Functions/m-p/1771734#M59733</link>
      <description>&lt;P&gt;Aggregate your final expression into dimension wise as per your chart, Example&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;Sum(Aggr(&lt;/FONT&gt;if($(FUNCTION)=0, 0,&amp;nbsp;(if($(FUNCTION)&amp;lt;5,&amp;nbsp;'*', $(FUNCTION))))&lt;FONT color="#FF0000"&gt;, Dim1, Dim2)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jan 2021 19:31:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Separating-Chart-Expression-into-Smaller-Functions/m-p/1771734#M59733</guid>
      <dc:creator>Anil_Babu_Samineni</dc:creator>
      <dc:date>2021-01-04T19:31:18Z</dc:date>
    </item>
    <item>
      <title>Re: Separating Chart Expression into Smaller Functions</title>
      <link>https://community.qlik.com/t5/App-Development/Separating-Chart-Expression-into-Smaller-Functions/m-p/1771818#M59746</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/130322"&gt;@jashinskyjm&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes you can, there is a little trick when you create the variable in the Variable Overview:&lt;/P&gt;&lt;P&gt;This is the expression you want to assign to a variable:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;sum(drug_overdose) + 0*sum({1&amp;lt;year_incidence={$(=concat(distinct year_incidence,','))}&amp;gt;} drug_overdose)&lt;/LI-CODE&gt;&lt;P&gt;This expression already contains SET analysis elements, something to keep in mind when you create a variable with this expression, the expression must start with an equal sign,&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;=sum(drug_overdose) + 0*sum({1&amp;lt;year_incidence={$(=concat(distinct year_incidence,','))}&amp;gt;} drug_overdose)&lt;/LI-CODE&gt;&lt;P&gt;Without the leading &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;=&lt;/STRONG&gt;&lt;/FONT&gt; sign in the expression, it will not work as you expect in the UI, see the screenshot of my test QVF illustrating this fact.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Variable_SET_01.png" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/46412iE6DDCD0FABF74AEE/image-size/large?v=v2&amp;amp;px=999" role="button" title="Variable_SET_01.png" alt="Variable_SET_01.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Variable_SET_02.png" style="width: 644px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/46413i818EA128A922E819/image-size/large?v=v2&amp;amp;px=999" role="button" title="Variable_SET_02.png" alt="Variable_SET_02.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Hope this helps,&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jan 2021 07:17:33 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Separating-Chart-Expression-into-Smaller-Functions/m-p/1771818#M59746</guid>
      <dc:creator>ArnadoSandoval</dc:creator>
      <dc:date>2021-01-05T07:17:33Z</dc:date>
    </item>
  </channel>
</rss>

