<?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: Comparing 2 fields in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Comparing-2-fields/m-p/275882#M1190498</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;sum(if(FieldA=FieldB,FieldC))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;sum(if(FieldA&amp;lt;FieldB,FieldC))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;sum(if(FieldA&amp;gt;FieldB,FieldC))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I believe set analysis can't work because it isn't sensitive to row.&amp;nbsp; So if you tell it FieldA=FieldB, I would expect this to work the same as FieldA={1,2,4,5}, which isn't what you want.&amp;nbsp; Ah, I was wrong.&amp;nbsp; It only works if a single value is selected for FieldB.&amp;nbsp; If you need the performance of set analysis, consider setting and using an indicator.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;,if(FieldA=FieldB,'='&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;,if(FieldA&amp;lt;FieldB,'&amp;lt;'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;,if(FieldA&amp;gt;FieldB,'&amp;gt;','?'))) as "A vs. B"&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;sum({&amp;lt;"A vs. B"={'='}&amp;gt;} FieldC)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;sum({&amp;lt;"A vs. B"={'&amp;lt;'}&amp;gt;} FieldC)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;sum({&amp;lt;"A vs. B"={'&amp;gt;'}&amp;gt;} FieldC)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could also do this if there's a unique ID associated with each row.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;sum({&amp;lt;ID={"=FieldA=FieldB"}&amp;gt;} FieldC)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, I expect the performance of that to be just as bad as the sum(if()), as both need to scan EVERY row in order to know what to sum.&lt;/P&gt;&lt;P&gt;See all three approaches in the attached example.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 12 Jul 2011 21:28:31 GMT</pubDate>
    <dc:creator>johnw</dc:creator>
    <dc:date>2011-07-12T21:28:31Z</dc:date>
    <item>
      <title>Comparing 2 fields</title>
      <link>https://community.qlik.com/t5/QlikView/Comparing-2-fields/m-p/275881#M1190497</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have what may be a simple question - each row of data has 3 fields with the corresponding values&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Field A has values 1,1,2,2,3,3,4,4,5,5&amp;nbsp; (10 values)&lt;/P&gt;&lt;P&gt;Field B has values 1,2,4,2,4,4,4,5,5,4&lt;/P&gt;&lt;P&gt;Field C has values 20,30, 20, 30 ,40 ,45,46, 47,50,60&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;how do I select rows where field A = field B to sum Field C - i.e. row 1, row 4 ,row 7, and row 9&lt;/P&gt;&lt;P&gt;and sum Field C i.e 20 + 30 + 46 + 50 = 146&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also need to know how to select rows where Field A value is less than Field B values i.e rows 2,3,5,6,8&lt;/P&gt;&lt;P&gt;and where Field A is greater than Field B i.e. row 10&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried set analysis&amp;nbsp; -&amp;nbsp;&amp;nbsp;&amp;nbsp; sum( {&amp;lt;Field A = Field B&amp;gt;} Field C)&amp;nbsp;&amp;nbsp;&amp;nbsp; but didn't work &lt;/P&gt;&lt;P&gt;also tried ﻿(for less than)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sum( {&amp;lt;Field A = {$=( &amp;lt; Field B)} &amp;gt;} FieldC)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and many other combinations and syntax&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jul 2011 20:45:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Comparing-2-fields/m-p/275881#M1190497</guid>
      <dc:creator />
      <dc:date>2011-07-12T20:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing 2 fields</title>
      <link>https://community.qlik.com/t5/QlikView/Comparing-2-fields/m-p/275882#M1190498</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;sum(if(FieldA=FieldB,FieldC))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;sum(if(FieldA&amp;lt;FieldB,FieldC))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;sum(if(FieldA&amp;gt;FieldB,FieldC))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I believe set analysis can't work because it isn't sensitive to row.&amp;nbsp; So if you tell it FieldA=FieldB, I would expect this to work the same as FieldA={1,2,4,5}, which isn't what you want.&amp;nbsp; Ah, I was wrong.&amp;nbsp; It only works if a single value is selected for FieldB.&amp;nbsp; If you need the performance of set analysis, consider setting and using an indicator.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;,if(FieldA=FieldB,'='&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;,if(FieldA&amp;lt;FieldB,'&amp;lt;'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;,if(FieldA&amp;gt;FieldB,'&amp;gt;','?'))) as "A vs. B"&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;sum({&amp;lt;"A vs. B"={'='}&amp;gt;} FieldC)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;sum({&amp;lt;"A vs. B"={'&amp;lt;'}&amp;gt;} FieldC)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;sum({&amp;lt;"A vs. B"={'&amp;gt;'}&amp;gt;} FieldC)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could also do this if there's a unique ID associated with each row.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;sum({&amp;lt;ID={"=FieldA=FieldB"}&amp;gt;} FieldC)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, I expect the performance of that to be just as bad as the sum(if()), as both need to scan EVERY row in order to know what to sum.&lt;/P&gt;&lt;P&gt;See all three approaches in the attached example.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jul 2011 21:28:31 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Comparing-2-fields/m-p/275882#M1190498</guid>
      <dc:creator>johnw</dc:creator>
      <dc:date>2011-07-12T21:28:31Z</dc:date>
    </item>
  </channel>
</rss>

