Note that there are some explanatory texts on larger screens.

plurals
  1. POSum of column values in sharepoint list if value for another column matches using C# and CAML
    text
    copied!<p>I am trying to get the value of manager in the sharepoint list and when the manager values are the same, i'm trying to add all the amounts then output the manager name and the sum.</p> <p>Here are the entries in the sharepoint list</p> <pre><code>Manager Amount 1 1000 2 2000 3 3000 4 500 1 1500 2 2500 </code></pre> <p>Then I should send an email that should have this output and return only the top 3 highest amounts:</p> <pre><code>Manager Amount 2 4500 3 3000 1 2500 </code></pre> <p>Here is my CAML Query</p> <pre><code>camlQuery.ViewXml = " &lt;Query&gt;&lt;Where&gt;&lt;And&gt;&lt;IsNotNull&gt;&lt;FieldRef Name='Manager' /&gt;&lt;/IsNotNull&gt;&lt;IsNotNull&gt;&lt;FieldRef Name='Amount' /&gt;&lt;/IsNotNull&gt;&lt;/And&gt;&lt;OrderBy&gt;&lt;FieldRef Name='Amount' Ascending='False' /&gt;&lt;/OrderBy&gt;&lt;/Where&gt;&lt;/Query&gt; "; </code></pre> <p>And Here is my Code</p> <pre><code> double iSum = 0; foreach (ListItem oListItem in collListItem) { FieldUserValue man = (FieldUserValue)oListItem["Manager"]; if(oListItem["Amount"].ToString() == null) continue; iSum += Convert.ToDouble(oListItem["Amount"].ToString()); Console.WriteLine("\nManager Name: " + man.LookupValue + " Amount: " + iSum.ToString()); message += "&lt;tr&gt;" + " &lt;td class='pdetails'&gt; " + man.LookupValue + "&lt;/td&gt; " + " &lt;td class='pdetails'&gt; " + iSum.ToString() + "&lt;/td&gt;&lt;/tr&gt; "; } </code></pre> <p>Kindly help me in fixing my caml query and foreach loop and how to get the expected output which is the sum of the amounts per manager. Please and thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload