<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Count function</title><link>https://community.appian.com/discussions/f/new-to-appian/21015/count-function</link><description>Why does the count() function return a 1 if I pass in a null? so when I run count({null}) this returns a 1 but to me I would logically think 0. Was hoping for someone to explain this to me, Thank you.</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Count function</title><link>https://community.appian.com/thread/81874?ContentTypeID=1</link><pubDate>Thu, 20 May 2021 19:51:08 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:08f6f84b-65ed-4fe7-a5e7-d575249f3e68</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;Agreed, in most of my systems sooner or later we&amp;#39;ve implemented an expression rule to do a null-safe length(), like &amp;quot;UTIL_arrayLength()&amp;quot; or similar - just to prevent errors when the inevitable &amp;quot;get length of a null&amp;quot; happens.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Count function</title><link>https://community.appian.com/thread/81872?ContentTypeID=1</link><pubDate>Thu, 20 May 2021 19:49:25 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:19a00a4e-4ed9-4a9e-8bc2-64b6eb197111</guid><dc:creator>Peter Lewis</dc:creator><description>&lt;p&gt;The one tricky thing about the length() function though is that you may also need to consider if the variable itself is null. For instance, both of these return the same:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;length({&amp;quot;test&amp;quot;})
count({&amp;quot;test&amp;quot;})&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The one below returns 1 for count and 0 for length:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;length({null})
count({null})&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;However, this one below actually fails when using length (and returns 1 for count()):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;length(null)
count(null)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So, if it&amp;#39;s possible that the value could be null and not in a list, it&amp;#39;s often good practice to pair your length function with a null check like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!data: null,
  if(
    isnull(local!data),
    0,
    length(local!data)
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Count function</title><link>https://community.appian.com/thread/81868?ContentTypeID=1</link><pubDate>Thu, 20 May 2021 18:49:16 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:57b7acf8-2f63-4626-8288-bfcf8a43f6e6</guid><dc:creator>ericm</dc:creator><description>&lt;p&gt;Thank you, that makes sense so count is also counting the null.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Count function</title><link>https://community.appian.com/thread/81867?ContentTypeID=1</link><pubDate>Thu, 20 May 2021 18:28:55 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:c1690d64-d1ac-496c-83a6-3ff60dda1bed</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;count()&lt;/em&gt;&lt;/strong&gt; intentionally returns the length of an array including nulls.&amp;nbsp; if you want to get the length of an array excluding nulls, then you would use &lt;strong&gt;&lt;em&gt;length()&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/62/pastedimage1621535345539v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/62/pastedimage1621535382271v2.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>