Search code examples
spotfire

spotfire how to show a trend in a calculted column


enter image description here

i have a data table like this. how do i create a calculated column to show if the quantity is increasing? say if the last quantity is higher than the second last quantity, then the result should be true else false.

eventually, i want to use a graphic table with a icon to represent it.

thank you


Solution

  • Two answers here, depending on if you want to look at it by Product or just at the entire data set as a whole.

    By Product

    • Insert calculated column: Rank([Date],"asc",[Product]) as [ProductRowNumber]
    • Insert calculated column: If([Quantity]>Min([Quantity]) over (Intersect([Product],Previous([ProductRowNumber]))),"TRUE","FALSE")

    Ignoring Product (Entire Data Set)

    • Insert calculated column: Rank([Date],"asc") as [RowNumber]

    • Insert calculated column: If([Quantity]>Min([Quantity]) over (Previous([RowNumber])),"TRUE","FALSE")

    Results

    +------------+---------+----------+------------------+-------------------+-----------+-------------------------+
    |    Date    | Product | Quantity | ProductRowNumber | IncreasingProduct | RowNumber | IncreasingEntireDataSet |
    +------------+---------+----------+------------------+-------------------+-----------+-------------------------+
    | 11/01/2016 | a       |        0 |                1 |                   |         1 |                         |
    | 11/02/2016 | a       |        1 |                2 | TRUE              |         2 | TRUE                    |
    | 11/03/2016 | a       |        2 |                3 | TRUE              |         3 | TRUE                    |
    | 11/04/2016 | a       |        3 |                4 | TRUE              |         4 | TRUE                    |
    | 11/05/2016 | a       |        4 |                5 | TRUE              |         5 | TRUE                    |
    | 11/06/2016 | a       |        5 |                6 | TRUE              |         6 | TRUE                    |
    | 11/07/2016 | a       |        6 |                7 | TRUE              |         7 | TRUE                    |
    | 11/08/2016 | a       |        7 |                8 | TRUE              |         8 | TRUE                    |
    | 11/09/2016 | a       |        8 |                9 | TRUE              |         9 | TRUE                    |
    | 11/10/2016 | a       |        9 |               10 | TRUE              |        10 | TRUE                    |
    | 11/11/2016 | a       |       10 |               11 | TRUE              |        11 | TRUE                    |
    | 11/12/2016 | b       |        0 |                1 |                   |        12 | FALSE                   |
    | 11/13/2016 | b       |        1 |                2 | TRUE              |        13 | TRUE                    |
    | 11/14/2016 | b       |        2 |                3 | TRUE              |        14 | TRUE                    |
    | 11/15/2016 | b       |        3 |                4 | TRUE              |        15 | TRUE                    |
    | 11/16/2016 | b       |        4 |                5 | TRUE              |        16 | TRUE                    |
    | 11/17/2016 | b       |        5 |                6 | TRUE              |        17 | TRUE                    |
    | 11/18/2016 | b       |        4 |                7 | FALSE             |        18 | FALSE                   |
    | 11/19/2016 | b       |        3 |                8 | FALSE             |        19 | FALSE                   |
    | 11/20/2016 | b       |        2 |                9 | FALSE             |        20 | FALSE                   |
    | 11/21/2016 | b       |        3 |               10 | TRUE              |        21 | TRUE                    |
    | 11/22/2016 | c       |        0 |                1 |                   |        22 | FALSE                   |
    | 11/23/2016 | c       |        1 |                2 | TRUE              |        23 | TRUE                    |
    | 11/24/2016 | c       |        2 |                3 | TRUE              |        24 | TRUE                    |
    | 11/25/2016 | c       |        3 |                4 | TRUE              |        25 | TRUE                    |
    | 11/26/2016 | c       |        2 |                5 | FALSE             |        26 | FALSE                   |
    | 11/27/2016 | c       |        1 |                6 | FALSE             |        27 | FALSE                   |
    | 11/28/2016 | c       |        2 |                7 | TRUE              |        28 | TRUE                    |
    | 11/29/2016 | c       |        2 |                8 | FALSE             |        29 | FALSE                   |
    +------------+---------+----------+------------------+-------------------+-----------+-------------------------+