<?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: Set analysis using one field if another field does not exist in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Set-analysis-using-one-field-if-another-field-does-not-exist/m-p/1569548#M41540</link>
    <description>&lt;P&gt;I believe so, but I would trust on your testing more than my word &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 15 Apr 2019 16:16:58 GMT</pubDate>
    <dc:creator>sunny_talwar</dc:creator>
    <dc:date>2019-04-15T16:16:58Z</dc:date>
    <item>
      <title>Set analysis using one field if another field does not exist</title>
      <link>https://community.qlik.com/t5/App-Development/Set-analysis-using-one-field-if-another-field-does-not-exist/m-p/1569269#M41510</link>
      <description>&lt;P&gt;Hi there experts&lt;/P&gt;&lt;P&gt;I have two tables, one with a work order and one with downtimes like below:&lt;/P&gt;&lt;P&gt;WO:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;WOId&lt;/TD&gt;&lt;TD&gt;Started&lt;/TD&gt;&lt;TD&gt;Ended&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2019/01/01&lt;/TD&gt;&lt;TD&gt;2019/01/15&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2019/01/05&lt;/TD&gt;&lt;TD&gt;2019/01/10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2019/01/09&lt;/TD&gt;&lt;TD&gt;2019/01/08&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2019/01/07&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Downtime:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;WOId&lt;/TD&gt;&lt;TD&gt;DowntimeType&lt;/TD&gt;&lt;TD&gt;DowntimeDays&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;0.5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When the two are concatenated have the following table:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;WOId&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Started&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Ended&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;DowntimeType&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;DowntimeDays&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#3366FF"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#3366FF"&gt;2019/01/01&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#3366FF"&gt;2019/01/15&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#3366FF"&gt;A&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#3366FF"&gt;5&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#3366FF"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#3366FF"&gt;2019/01/01&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#3366FF"&gt;2019/01/15&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#3366FF"&gt;B&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#3366FF"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#FF6600"&gt;2&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF6600"&gt;2019/01/05&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF6600"&gt;2019/01/10&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#3366FF"&gt;3&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#3366FF"&gt;2019/01/09&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#3366FF"&gt;2019/01/08&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#3366FF"&gt;A&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#3366FF"&gt;0.5&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#3366FF"&gt;3&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#3366FF"&gt;2019/01/09&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#3366FF"&gt;2019/01/08&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#3366FF"&gt;C&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#3366FF"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#FF6600"&gt;4&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF6600"&gt;2019/01/07&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I want to know if it is possible with set analysis (and hopefully not using IF statements) to do the following:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;If there is downtime for a work order (WOId), I want the sum of the downtime. However, if there is not downtime, I want to get the difference between the Ended and Started dates &lt;U&gt;provided the Ended is after the Started&lt;/U&gt;.&lt;/P&gt;&lt;P&gt;I got this to work partially by using Alt the following expression:&lt;/P&gt;&lt;P&gt;Sum({&amp;lt;WOId = {'=([Ended] - [Started]) &amp;gt;= 0'}&amp;gt;} Alt(DowntimeDays, Ended - Started))&lt;/P&gt;&lt;P&gt;However, I do not want the set expression's conditions to be taken into account when there is actual downtime (I do not care if the Ended was before the Started if there was actual downtime). Below is the expected output:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;WOId&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Downtime&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;1.5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can I do this with pure set analysis or should I use an If statement like below (which works)?&lt;/P&gt;&lt;P&gt;If(Sum(DowntimeDays)&amp;gt;0,Sum(DowntimeDays),Sum({&amp;lt;WOId = {'=([Ended] - [Started]) &amp;gt;= 0'}&amp;gt;} Ended - Started))&lt;/P&gt;&lt;P&gt;I try to stay away from IF statements with large datasets for performance reasons after reading this thread:&amp;nbsp;&lt;A href="https://community.qlik.com/t5/QlikView-App-Development/If-statement-vs-set-analysis/td-p/591661" target="_blank" rel="noopener"&gt;https://community.qlik.com/t5/QlikView-App-Development/If-statement-vs-set-analysis/td-p/591661&lt;/A&gt;&lt;/P&gt;&lt;P&gt;My real dataset is obviously a lot bigger and more complex than this example &lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://community.qlik.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;.&lt;/P&gt;&lt;P&gt;Thank you in advance for any help!&lt;/P&gt;&lt;P&gt;Mauritz&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/46628"&gt;@sunny_talwar&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/18624"&gt;@Gysbert_Wassenaar&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/6622"&gt;@hic&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/22245"&gt;@swuehl&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 09:28:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Set-analysis-using-one-field-if-another-field-does-not-exist/m-p/1569269#M41510</guid>
      <dc:creator>Mauritz_SA</dc:creator>
      <dc:date>2019-04-15T09:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: Set analysis using one field if another field does not exist</title>
      <link>https://community.qlik.com/t5/App-Development/Set-analysis-using-one-field-if-another-field-does-not-exist/m-p/1569355#M41517</link>
      <description>&lt;P&gt;How about this&lt;/P&gt;&lt;PRE&gt;RangeSum(
  Sum(DowntimeDays),
  Sum({&amp;lt;WOId = {"=([Ended] - [Started]) &amp;gt;= 0 and Len(Trim(DowntimeDays)) = 0"}&amp;gt;} Ended - Started)
)&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Apr 2019 11:33:19 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Set-analysis-using-one-field-if-another-field-does-not-exist/m-p/1569355#M41517</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2019-04-15T11:33:19Z</dc:date>
    </item>
    <item>
      <title>Re: Set analysis using one field if another field does not exist</title>
      <link>https://community.qlik.com/t5/App-Development/Set-analysis-using-one-field-if-another-field-does-not-exist/m-p/1569480#M41520</link>
      <description>&lt;P&gt;Hi Sunny&lt;/P&gt;&lt;P&gt;Thanks for the reply. My understanding of rangesum is that it will return the sum of all the values. In your answer below I only want to get the second argument if the work order has no Downtime against it (if the first argument is 0).&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mauritz&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 14:06:31 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Set-analysis-using-one-field-if-another-field-does-not-exist/m-p/1569480#M41520</guid>
      <dc:creator>Mauritz_SA</dc:creator>
      <dc:date>2019-04-15T14:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: Set analysis using one field if another field does not exist</title>
      <link>https://community.qlik.com/t5/App-Development/Set-analysis-using-one-field-if-another-field-does-not-exist/m-p/1569543#M41537</link>
      <description>&lt;P&gt;Have you tried it? Did you see the part highlighted in red?&lt;/P&gt;&lt;PRE&gt;Sum({&amp;lt;WOId = {"=([Ended] - [Started]) &amp;gt;= 0 &lt;FONT color="#FF0000"&gt;and Len(Trim(DowntimeDays)) = 0&lt;/FONT&gt;"}&amp;gt;} Ended - Started)&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Apr 2019 16:03:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Set-analysis-using-one-field-if-another-field-does-not-exist/m-p/1569543#M41537</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2019-04-15T16:03:18Z</dc:date>
    </item>
    <item>
      <title>Re: Set analysis using one field if another field does not exist</title>
      <link>https://community.qlik.com/t5/App-Development/Set-analysis-using-one-field-if-another-field-does-not-exist/m-p/1569546#M41539</link>
      <description>&lt;P&gt;Hi Sunny&lt;/P&gt;&lt;P&gt;Sorry, I missed it when I scrolled. I will have a look and let you know.&lt;/P&gt;&lt;P&gt;In your opinion, will this be a better approach to using the if statement in my original post?&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mauritz&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 16:06:57 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Set-analysis-using-one-field-if-another-field-does-not-exist/m-p/1569546#M41539</guid>
      <dc:creator>Mauritz_SA</dc:creator>
      <dc:date>2019-04-15T16:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: Set analysis using one field if another field does not exist</title>
      <link>https://community.qlik.com/t5/App-Development/Set-analysis-using-one-field-if-another-field-does-not-exist/m-p/1569548#M41540</link>
      <description>&lt;P&gt;I believe so, but I would trust on your testing more than my word &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 16:16:58 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Set-analysis-using-one-field-if-another-field-does-not-exist/m-p/1569548#M41540</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2019-04-15T16:16:58Z</dc:date>
    </item>
    <item>
      <title>Re: Set analysis using one field if another field does not exist</title>
      <link>https://community.qlik.com/t5/App-Development/Set-analysis-using-one-field-if-another-field-does-not-exist/m-p/1569637#M41545</link>
      <description>&lt;P&gt;Hi Sunny&lt;/P&gt;&lt;P&gt;I got it working with a slight variation:&lt;/P&gt;&lt;PRE&gt;RangeSum(
  Sum(DowntimeDays),
  Sum({&amp;lt;WOId = {"=([Ended] - [Started]) &amp;gt;= 0 and &lt;FONT color="#FF0000"&gt;Sum(DowntimeDays)&lt;/FONT&gt; = 0"}&amp;gt;} Ended - Started)
)&lt;/PRE&gt;&lt;P&gt;I guess the Len(Trim()) function did not work because I could have more than one downtime entry for a work order. I did not realise that you could use multiple conditions within a set expression between quotes (although it seems obvious now that you pointed it out).&lt;/P&gt;&lt;P&gt;I will let you know if I can find any change in the performance between your formula and the IF statement.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mauritz&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 19:55:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Set-analysis-using-one-field-if-another-field-does-not-exist/m-p/1569637#M41545</guid>
      <dc:creator>Mauritz_SA</dc:creator>
      <dc:date>2019-04-15T19:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: Set analysis using one field if another field does not exist</title>
      <link>https://community.qlik.com/t5/App-Development/Set-analysis-using-one-field-if-another-field-does-not-exist/m-p/1569689#M41548</link>
      <description>&lt;P&gt;Good to know that you managed to figure it out.&lt;/P&gt;&lt;P&gt;Best,&lt;BR /&gt;Sunny&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 23:58:57 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Set-analysis-using-one-field-if-another-field-does-not-exist/m-p/1569689#M41548</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2019-04-15T23:58:57Z</dc:date>
    </item>
  </channel>
</rss>

