5 Replies Latest reply on Sep 20, 2013 1:22 PM by Robert Prince

# PREVIOUS_VALUE vs LOOKUP([expr],-1)

Hi

I created a table calc to find the previous value of a running sum. My first attempt was to use PREVIOUS_VALUE, but to no avail. I ended up using LOOKUP(..., -1) which does work. The attached workbook shows the calcs.

Can anyone explain why the PREVIOUS_VALUE calc doesn't work?

Thanks

Andy

• ###### 1. Re: PREVIOUS_VALUE vs LOOKUP([expr],-1)

Lookup is based on an expression, so I consider it based on the result of another field, while Previous is self referring, referring to the result of the calculated field it is a part of. You can replicate a running sum with previous, for example:

```RUNNING_SUM(SUM([Profit]))

=
PREVIOUS_VALUE(0)+SUM([Profit])
```

the zero (0) means, then there is not previous value for the result of this calculation, for the first row in the partition, use 0 as the previous value.

Just like other Table Calculation functions, there must be some kind of aggregate function in the expression.

Does that help?

• ###### 2. Re: PREVIOUS_VALUE vs LOOKUP([expr],-1)

Joe, that is a nice piece of information,    using (0)  with previous_value.    Thanks

• ###### 3. Re: PREVIOUS_VALUE vs LOOKUP([expr],-1)

here's the attachment I meant to put in the original post. however, I think Joe's answered the question!

• ###### 4. Re: PREVIOUS_VALUE vs LOOKUP([expr],-1)

Andy,

in your workbook, there is a comment at hat says:

"I am trying to get the Previous running sum value calc field to show, um, the previous running sum value, rather than the Features Added value. Help!"

Because you want to display the result of another table calculation (and some other row), and not use a self referencing function,

`LOOKUP([Running Sum Table Calc] -1)`
is what you are looking for.

• ###### 5. Re: PREVIOUS_VALUE vs LOOKUP([expr],-1)

Hi,

I want to use the lookup function on current monthly data against previous monthly data, but when I filter out the previous month the lookup function returns empty (because the previous months' data is filtered).   How can I apply the lookup function using the previous monthly data AND yet let users filter by month to only view 1 month at a time?

Thanks

Bob