<?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: Sum column in collection - C# code stage in Product Forum</title>
    <link>https://community.blueprism.com/t5/Product-Forum/Sum-column-in-collection-C-code-stage/m-p/101537#M48485</link>
    <description>Thanks for your answer &lt;A class="user-content-mention" data-sign="@" data-contactkey="e42d12b2-a3f6-4f36-a821-9db8ee48b837" data-tag-text="@Nicholas Zejdlik" href="https://community.blueprism.com/network/profile?UserKey=e42d12b2-a3f6-4f36-a821-9db8ee48b837" data-itemmentionkey="fc2c5aa3-d4fd-4017-bd67-b73a789f98c6"&gt;@Nicholas Zejdlik&lt;/A&gt;!&lt;BR /&gt;&lt;BR /&gt;I get this ​error: Compiler error at line 1: Unexpected character '​'&lt;BR /&gt;&lt;BR /&gt;You got any ideas for this?</description>
    <pubDate>Thu, 04 Feb 2021 15:26:00 GMT</pubDate>
    <dc:creator>KarinaHansen</dc:creator>
    <dc:date>2021-02-04T15:26:00Z</dc:date>
    <item>
      <title>Sum column in collection - C# code stage</title>
      <link>https://community.blueprism.com/t5/Product-Forum/Sum-column-in-collection-C-code-stage/m-p/101535#M48483</link>
      <description>&lt;SPAN&gt;Hi&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm looking to summarize all values in a specified column in a collection through a code stage (not looping).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In this collection called "Collection", I want a sum of all values in column "Numbers" in a data item.&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="https://www.rpaforum.net/attachments/1612435555473-png.5857/" target="_blank" class="js-lbImage" rel="noopener"&gt;&lt;IMG src="https://www.rpaforum.net/data/attachments/5/5857-376133c65811ef97f9123162dc3ab387.jpg" class="bbImage img-responsive" alt="1612435555473.png" /&gt;&lt;/A&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't read or write C# very well, so can someone provide a code that will work for this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried to use the compute method, with no luck (&lt;/SPAN&gt;&lt;A href="https://docs.microsoft.com/en-us/dotnet/api/system.data.datatable.compute?redirectedfrom=MSDN&amp;amp;view=net-5.0#System_Data_DataTable_Compute_System_String_System_String_" target="_blank" class="link link--external" rel="nofollow noopener"&gt;MSDN&lt;/A&gt;&lt;SPAN&gt;&lt;SPAN&gt;).&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;PRE class="language-csharp"&gt;&lt;CODE&gt;private void ComputeBySalesSalesID(DataSet dataSet) 

{ 
   DataTable table; 
   table = dataSet.Tables["Collection"]; 

   object sumObject; 
   sumObject = table.Compute("Sum(Numbers)", ""); 
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;Thanks a lot!&lt;/SPAN&gt;</description>
      <pubDate>Thu, 04 Feb 2021 12:22:05 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/Sum-column-in-collection-C-code-stage/m-p/101535#M48483</guid>
      <dc:creator>KarinaHansen</dc:creator>
      <dc:date>2021-02-04T12:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: Sum column in collection - C# code stage</title>
      <link>https://community.blueprism.com/t5/Product-Forum/Sum-column-in-collection-C-code-stage/m-p/101536#M48484</link>
      <description>I find it easier to use Linq myself - here's a code stage that should do what you're looking for:&lt;BR /&gt;
&lt;PRE class="language-csharp"&gt;&lt;CODE&gt;// Inputs: 
// Collection (collection)
// Column Name (text)
// 
// Outputs:
// Total (number)
//
Total = Collection.AsEnumerable().Sum(x =&amp;gt; (decimal)x[Column_Name]);​&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I had to include System.Linq and System.Data.DataSetExtensions in the namespaces on the global code tab, as well as a reference to System.Linq.dll and System.Core.dll.&lt;/P&gt;
&lt;BR /&gt;</description>
      <pubDate>Thu, 04 Feb 2021 14:24:47 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/Sum-column-in-collection-C-code-stage/m-p/101536#M48484</guid>
      <dc:creator>NicholasZejdlik</dc:creator>
      <dc:date>2021-02-04T14:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: Sum column in collection - C# code stage</title>
      <link>https://community.blueprism.com/t5/Product-Forum/Sum-column-in-collection-C-code-stage/m-p/101537#M48485</link>
      <description>Thanks for your answer &lt;A class="user-content-mention" data-sign="@" data-contactkey="e42d12b2-a3f6-4f36-a821-9db8ee48b837" data-tag-text="@Nicholas Zejdlik" href="https://community.blueprism.com/network/profile?UserKey=e42d12b2-a3f6-4f36-a821-9db8ee48b837" data-itemmentionkey="fc2c5aa3-d4fd-4017-bd67-b73a789f98c6"&gt;@Nicholas Zejdlik&lt;/A&gt;!&lt;BR /&gt;&lt;BR /&gt;I get this ​error: Compiler error at line 1: Unexpected character '​'&lt;BR /&gt;&lt;BR /&gt;You got any ideas for this?</description>
      <pubDate>Thu, 04 Feb 2021 15:26:00 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/Sum-column-in-collection-C-code-stage/m-p/101537#M48485</guid>
      <dc:creator>KarinaHansen</dc:creator>
      <dc:date>2021-02-04T15:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: Sum column in collection - C# code stage</title>
      <link>https://community.blueprism.com/t5/Product-Forum/Sum-column-in-collection-C-code-stage/m-p/101538#M48486</link>
      <description>Is the language set to C#? I get a similar compiler error if I'm using VB as the language instead of C#. If it is set to C#, perhaps try typing it out manually? Maybe copy/paste got some odd unicode character in there.&lt;BR /&gt;&lt;BR /&gt;The VB equivalent would be this: &lt;CODE&gt;Total = Collection.AsEnumerable().Sum(Function (x) CType(x(Column_Name), Decimal))&lt;/CODE&gt;</description>
      <pubDate>Thu, 04 Feb 2021 15:38:51 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/Sum-column-in-collection-C-code-stage/m-p/101538#M48486</guid>
      <dc:creator>NicholasZejdlik</dc:creator>
      <dc:date>2021-02-04T15:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: Sum column in collection - C# code stage</title>
      <link>https://community.blueprism.com/t5/Product-Forum/Sum-column-in-collection-C-code-stage/m-p/101539#M48487</link>
      <description>You were absolutely right! I typed it in instead of copy/pasting and the error disappeared.&lt;BR /&gt;&lt;BR /&gt;But then I got a reference error. I googled for a while and found out that System.Data.DataSetExtensions.dll had to be added too.&lt;BR /&gt;&lt;BR /&gt;It works now! Thanks a bunch &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Thu, 04 Feb 2021 19:42:41 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/Sum-column-in-collection-C-code-stage/m-p/101539#M48487</guid>
      <dc:creator>KarinaHansen</dc:creator>
      <dc:date>2021-02-04T19:42:41Z</dc:date>
    </item>
  </channel>
</rss>

