3 Replies Latest reply: May 24, 2018 1:34 PM by Gabriel Oluwaseye RSS

    How to use conditional peek/previous

    Markus Riebeling

      I'm sorry if this has been asked before, but I couldn't find anything on it.  

      Lets say I have the following data:

       

      Some_Data:

      Load * Inline [

      Id, Group, Value

      1, A, 10

      2, B, 10

      3, C, 20

      4, B, 15

      5, A , 30

      ];

       

      I would like to Load this data and add a column (foo) that adds the previous row's value of the last identical group.

      So the desired loaded table would look like:

      IDGroupValuefoo
      1A1010
      2B1010
      3C2020
      4B1525 // ID4+ID2
      5A3040 // ID5+ID1

       

      If I use 'Previous(Value) + Value as foo' it will not consider the Group column. With Peek() I need to specify the row index.

      Maybe I can iterate throw the Data-set to find the last record with the same 'Group', and use the index for Peek(), but I don't know how to in Qlik.

       

      Can someone help me?