|Summary||This article will demonstrate more of the scripts that can be used in calculation arithmetic. Here we will concentrate on how to sum up calculations, specifically, to give a cumulative vertical % calculation|
|Applies to||Askia Analyse.|
|Written for||Researchers, Developers, Data Processors.|
|Keywords||Cumulative, Crossed calculation, Table arithmetic, Forloops, Coordinates, data, Calculation arithmetic, Percentage down, vertical %.|
The .qes file and portfolio containing the examples discussed is attached: Table Arithmetic Examples 7.rar.
In Analyse, there is a pre-set calculation for Cumulative % on flat calculations i.e. table with only variable in rows (no columns). However, if we want to do this with columns involved (crossed calculations) then there is no pre-set option.
We can get around this by using table arithmetic to add a calculation which will sum up each pre-set vertical %.
I will now talk through the steps / syntax used to achieve the above table where we sum v% into a new calculation we have added, 'Cumulative %'.
First insert a calculation of type: Calculation arithmetic
Hit the script button and enter the syntax shown above (and contained in the example file).
The points of note here are as follows:
If CurrentCell.Row.Index = 1 Then
Row.Index is a sequential number assigned to each response in each variable in the rows. When we are looking at the first response in the rows i.e. Row.Index = 1 then do the following:
Return the value for the third calculation (v%)
Then, for every next occurrence of this calculation, we add the current (row's value of) v%: Calc(3)
to the last (row's value of) Cumulative %: CurrentTable.GetCell(CurrentCell.X,CurrentCell.Y-4).Value
This is the row 4 rows above the current one, hence we use: CurrentCell.Y-4
There is a detailed article about Row, Column & Edge Index keywords here.