Search code examples
sortingcalculated-columnsspotfire

Sum data in one column in a specific order in Spotfire


Does anyone know how to create a calculated column (in Spotfire) that will sum data in order of increasing values contained within another column?

For example, what would the expression be to Sum data in [P] in increasing order of [K], for each [Well]

Some example data:

Well Depth P K
A 85 0.191 108
A 85.5 0.192 102
A 87 0.17 49
A 88 0.184 47
A 89 0.192 50
B 298 0.215 177
B 298.5 0.2 177
B 300 .017 105
B 301 0.23 200

Solution

  • You can use:

    Sum([P]) OVER (intersect([Well],AllPrevious([K])))

    This returns the cumulative sum of P in order of K per Well in ascending order of K.

    Well    K   P   Cumulative Sum of P
    A   47  0,184   0,184
    A   49  0,17    0,354
    A   50  0,192   0,546
    A   102 0,192   0,738
    A   108 0,191   0,929
    B   105 0,017   0,017
    B   177 0,215   0,432
    B   177 0,2     0,432
    B   200 0,23    0,662
    

    Edit Based on OP's comment:

    you can use to get the cumulative sum in descending order of K:

    Sum([P]) OVER (intersect([Well],AllNExt([K])))