Morning All,
I am needing assistance with a calculation process, which performs calculations on a group of records.
Here is a breakdown of my requirement:
Col1 = Always same value.
Col2 = Grouping Column, and will have the same value for 5/6/7 records for example.
Col3 = Date
Col4 = Amount 1
Col5 = Amount 2
Col6 = Amount 3 (to be derived as part of this code)
Col7 = Amount 4 (to be derived as part of this code)
Here is an example piece of input data:
I need to perform inter row calculations for each group of data (Col2 e.g. All the 00000001 records together):
- Take the first group of records (all 00000001 values in Col2):
- If the record is the first record in the array, Amount 3 needs to be set to 100.
- For all other records, it needs to be: "(Col5 current record / Col5 First record)*100"
E.g. Second record -- "(80,000/110,000)*100"
Third Record -- "(77,000/110,000)*100"
And so on....
Output Result:
- Using the data derived above, I now need to find the midpoint values:
- I need to take the current row col6 value and add it together with the row below col6 value (unless it is the last record of the group, and therefore it will be 0), and then divide by 2 to get the midpoint "(Col6 current record + Col6 below record)/2"
E.g. First Record --
(100+72.72727273)/2
Second Record --
(72.72727273+70)/2
And so on....
Output Result:
Any help would be much appreciated. I am sure I could perform the above via a normal Linux Loop function, however this will be running over large volumes of data, and therefore I am sure something like Awk will be more efficient.