I just can't seem to wrap my head around this... I have a sequence that look a bit like this:
A 1 1 50
A 1 2 50
A 2 1 20
A 2 2 60
B 1 1 35
B 1 2 35
C 1 1 80
D 1 1 12
D 1 2 12
D 1 3 15
D 2 1 12
What I need to do is to set those last column values to 0, where they are not the last value. So for example I need to set A11 to 0 because there is an A12. And I need to set A21 to 0, because there is an A22. B11 must be 0, because there is a B12. C11 is left, since there is no C12. D11 and D12 goes 0 because of D13, and D21 is left like it is.
In the actual dataset, column 1 is usernames, column 2 is dates, column 3 is login times and the last is an amount. And I need to set all those amounts, that are not connected with the last login time on a certain date for a certain user to 0.
Anyone that is able to do this in an easy way? I'm thinking multiple nested foreach statements or joining and grouping etc etc, but I can't decide how to do it best... or how to do it at all really...
(And please do edit my title if you come up with a better one!)
More info
Sorry, I should of course have told you more about the language and such. I am using C# and .NET 3.5. And I am using Linq to SQL to fetch the data from the database, and I have all that data as objects (Of a simple kind of container type class) in a generic List. I wish I could have just adjusted the query to only get the last rows, but the problem is that this data is going into a report, and all of the rows has to be displayed. I was hoping that I could do this in the report, but this seems to be not so easy. Or at least I have no clue how to do it, and haven't gotten any working answers either. So this is why I figure I need to copy that column and clear out those duplicate values. So that I can display the column with all values, and then do the summing on the column that only has the last values. Hope that made sense :P
Oh, and also, to clear up the dates and login times in separate columns issue: Thing is that they are both DateTimes, and the date doesn't need to have the same date as the login datetime. It is a weird issue caused by that in what I am working with a day may not need to be 00:00 to 23:59. A day may start at 3:00 in the morning for example.
Update
Just figured out that this whole issue might be solved in a different way... (And probably even should be) By creating a new column (In my case a new property) and then copy only those last values over into that new property. But again I would have to find all those values... So kind of same problem as the one I already have but a bit backwards or what to call it.