Hudikwebb IT

Hudikwebb IT

  • NA
  • 21
  • 578

Sum of duplicated items Tuple C#

Aug 16 2018 2:23 PM
I have a data in a tuple C# I will calcaulate the sum of the last column grouped by month. my program gives wrong results as shown in the table below. 
 
The program  is here :
  1. var q1 = from x in Vinst  
  2.                     group x by x.Item1 into g  
  3.                     let count = g.Count()  
  4.                     orderby count descending  
  5.                     select new { Value = g.Key, Count = count};  
  6.   
  7.             double sum = 0.0;//= (from x in Vinst where x.Item1.Equals("augusti") select x.Rest.Item2).Sum();  
  8.             int k = 0;  
  9.             foreach (var lst in Vinst)  
  10.             {  
  11.                 sum += lst.Rest.Item2; k++;  
  12.                 richTextBox7.AppendText("Vinst Data" + "\t" + lst.Item1 + "\t" + lst.Item2 + "\t" + lst.Item3 + "\t" + lst.Item4 + "\t" + lst.Item5 + "\t" + lst.Item6 +"\t" + lst.Item7+ "\t" + lst.Rest.Item1 + "\t" + lst.Rest.Item2 + "\n");  
  13.   
  14.                 foreach (var x in q1)  
  15.                     {  
  16.                         if (k == x.Count)  
  17.                             richTextBox7.AppendText("\nData summa" + " " + sum + "\n");  
  18.                     }  
  19.             }  
july     GBP     6000    13        400    19500    1500    5200    800
                                                                           Data sum 800
july     SAR     1000    2          400    1200    600    800    200
july     USD     4500    8.95    500    15993    1787 4475    25
                                                                        Data sum 1025
august USD     5700    8.5    600    5950       700    5100    600
 
The correct result should be like this
 
july     GBP     6000    13     400    19500    1500    5200    800
july     SAR     1000    2       400    1200       600    800       200
july     USD     4500    8.95  500    15993    1787    4475    25
                                                                           Data sum 1025
august USD    5700    8.5    600    5950       700    5100    600
                                                                              data sum 600

Answers (3)