Question : LINQ Aggregated Multiply

Date,Symbol,Rate
6/10/2010,XYZ,2.49
5/10/2010,ABC,10.21
9/10/2010,XYZ,1.11
12/8/2010,EFG,6.74
12/10/2010,XYZ,3.81

The table above is my source table and
the table below is the target view i would like to have.

Date,Symbol,Rate,CalculatedRate
6/10/2010,XYZ,2.49,10.530459
5/10/2010,ABC,10.21.10.21
9/10/2010,XYZ,1.11,4.2291
12/8/2010,EFG,6.74,6.74
12/10/2010,XYZ,3.81,3.81

CalculatedRate calculation starts from the last record to first record within same symbols.
first values are exactly same with rate and after that multiply with previous one

e.g.
latest XYZ is at 12/10/2010 and rate is 3.81 which sets CalculatedRate as same with Rate which is 3.81
next XYZ is at 9/10/2010 and rate is 1.11 which means we need to multiply it with previous one 1.11*3.81=4.2291
next XYZ is at 6/10/2010 and rate is 2.49 multiply it with previous one 2.49*4.2291=10.530459

P.S.: I need a solution with LINQ

Thank you for your time and atention.

Answer : LINQ Aggregated Multiply

Hi cilerler:

To your last question, "About "Let clause doesn't have access for previous value" that's the whole point of this question, I mean it should have it, since Linq has Aggregate ability.", As I stated in your other question you have and my answer re-posted below it can not be accomplished with the Aggregate method

From Microsoft documentation: http://msdn.microsoft.com/en-us/library/bb548651.aspx
The Aggregate method makes it simple to perform a calculation over a sequence of values. This method works by calling func one time for each element in source. Each time func is called, Aggregate passes both the element from the sequence and an aggregated value (as the first argument to func). The first element of source is used as the initial aggregate value. The result of func replaces the previous aggregated value. Aggregate returns the final result of func.

The Aggregate method works on a sequence from beginning to end and returns a single value. This is the same for Count, Sum, Min, Max, and Average methods so will not serve your needs.

Fernando
Random Solutions  
 
programming4us programming4us