LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Recoffset function

    Employee
    Posted 05-15-2015 05:23

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: zon

    Hi,

    Does anybody know if there's a function that allows me to use a value from a field that is in a previous line of a table?
    Like RECOFFSET from excel.

    Best Regards,
    NOS


  • 2.  RE: Recoffset function

    Employee
    Posted 05-15-2015 06:20

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: stonysmith

    Do you want to go back just one record, or more than one?

    There is a way to retain a value from the previous record. Here is one simple example

    if firstExec then pv = 0
    
    if 'MyColumn' <> pv then  changed = true else changed = false
    
    emit *,changed
    
    pv = 'MyColumn'
    The trick to making this work is:
    1) must set an initial value
    2) must assign the value you want to retain to the next record AFTER the emit


  • 3.  RE: Recoffset function

    Employee
    Posted 05-15-2015 06:40

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: zon

    I just need to retain the previous.
    That's how a changed your code:

    if firstExec then BACheck = ""
    if BA <> BACheck then COUNT = 1 else COUNT = COUNT + 1
    emit *, COUNT
    BACheck = BA

    I tried, but is returning always 1. I think he writes all the table in the first emit.


  • 4.  RE: Recoffset function

    Employee
    Posted 05-15-2015 07:12

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: stonysmith

    The only reason I'd see that happening is if each record has a new value for BA.
    One question: are you doing the above in a fliter or an agg? If you are doing an agg, the emit is controlled by the GroupBy expression.

    I've included a graph that uses your logic inside a filter.. you'll see that it works fine.
    Attachments:
    test.brg


  • 5.  RE: Recoffset function

    Employee
    Posted 05-15-2015 08:23

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: zon

    Perfect!
    It works

    Many thanks!
    NOS, Portugal