<?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 Check if a Value in a field exists in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Check-if-a-Value-in-a-field-exists/m-p/174465#M43290</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I am writing a macro and I am trying to check to make sure the value exists in the field and if it does not I would like to write an error to my log file. I have tried declaring a variable and hoping that it would return True if it was able to be selected and False if not, but if my value exists it is selected and my variable returns False. My code is:&lt;/P&gt;&lt;P&gt;checkValue = Document.Fields(Attr1).Select(Attr2)&lt;/P&gt;&lt;P&gt;if checkValue is true then&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;Else&lt;/P&gt;&lt;P&gt;lg.WriteLine("Command could not be done because the value does not exist in the field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 25 Aug 2010 15:56:08 GMT</pubDate>
    <dc:creator />
    <dc:date>2010-08-25T15:56:08Z</dc:date>
    <item>
      <title>Check if a Value in a field exists</title>
      <link>https://community.qlik.com/t5/QlikView/Check-if-a-Value-in-a-field-exists/m-p/174465#M43290</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I am writing a macro and I am trying to check to make sure the value exists in the field and if it does not I would like to write an error to my log file. I have tried declaring a variable and hoping that it would return True if it was able to be selected and False if not, but if my value exists it is selected and my variable returns False. My code is:&lt;/P&gt;&lt;P&gt;checkValue = Document.Fields(Attr1).Select(Attr2)&lt;/P&gt;&lt;P&gt;if checkValue is true then&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;Else&lt;/P&gt;&lt;P&gt;lg.WriteLine("Command could not be done because the value does not exist in the field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Aug 2010 15:56:08 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Check-if-a-Value-in-a-field-exists/m-p/174465#M43290</guid>
      <dc:creator />
      <dc:date>2010-08-25T15:56:08Z</dc:date>
    </item>
    <item>
      <title>Check if a Value in a field exists</title>
      <link>https://community.qlik.com/t5/QlikView/Check-if-a-Value-in-a-field-exists/m-p/174466#M43291</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;checkValue =ActiveDocument.Evaluate("count({$&amp;lt;Field={'Value'}&amp;gt;} Field)")&lt;/P&gt;&lt;P&gt;If checkValue&amp;gt;0, value exists&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Aug 2010 19:36:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Check-if-a-Value-in-a-field-exists/m-p/174466#M43291</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-08-25T19:36:09Z</dc:date>
    </item>
    <item>
      <title>Check if a Value in a field exists</title>
      <link>https://community.qlik.com/t5/QlikView/Check-if-a-Value-in-a-field-exists/m-p/174467#M43292</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Tried to use your statement but it doesnt work for me.&lt;/P&gt;&lt;P&gt;if my field name is f and the value is v, what should this statement look like?&lt;/P&gt;&lt;P&gt;checkValue =ActiveDocument.Evaluate("count({$&amp;lt;Field={'Value'}&amp;gt;} Field)")&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Feb 2011 13:55:58 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Check-if-a-Value-in-a-field-exists/m-p/174467#M43292</guid>
      <dc:creator />
      <dc:date>2011-02-01T13:55:58Z</dc:date>
    </item>
    <item>
      <title>Check if a Value in a field exists</title>
      <link>https://community.qlik.com/t5/QlikView/Check-if-a-Value-in-a-field-exists/m-p/174468#M43293</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It will be&lt;BR /&gt;checkValue =ActiveDocument.Evaluate("count({$&amp;lt;f={'v'}&amp;gt;} f)")&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Feb 2011 16:28:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Check-if-a-Value-in-a-field-exists/m-p/174468#M43293</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-02-01T16:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: Check if a Value in a field exists</title>
      <link>https://community.qlik.com/t5/QlikView/Check-if-a-Value-in-a-field-exists/m-p/174469#M43294</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This works great! Here's a snippit of what I'm doing in C#.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I added DISTINCT so that the output of 1 means the value exists in that field while an output of 0 means it does not exist&lt;/LI&gt;&lt;LI&gt;I added brackets "[]" around the field name so it will work with field names containing spaces and return 0 if the field name is empty&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;string countString = @"COUNT(DISTINCT{$&amp;lt;[" + fieldName + @"]={'" + value + @"'}&amp;gt;}[" + fieldName + @"])";&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt; if (Int32.Parse(ReportControl.QVDoc.Evaluate(countString)) == 1)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //whatever&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jan 2016 15:23:38 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Check-if-a-Value-in-a-field-exists/m-p/174469#M43294</guid>
      <dc:creator>TKendrick20</dc:creator>
      <dc:date>2016-01-19T15:23:38Z</dc:date>
    </item>
  </channel>
</rss>

