2 Replies Latest reply on Mar 28, 2013 1:34 PM by sira.sasitorn

# Table Calc - Taking value from the row above

Hi,

I'm trying to convert a formula in Excel to Tableau calculations. For example, in the attached spreadsheet, I'm trying to convert column C formula into Tableau syntax. However, I don't know if it is possible to reference the row above. For example, the logic to calculate column C is:

A               B                    C                        D

 6 11/28/2012 153 153 7 11/28/2012 246 246 7 11/28/2012 246 0

If the value in column A is the same as the value above in column A (A2 = A1), and, value in column B is the same as the value above in column B (B2 = B1), then, take the previous value (column C 1) + column D (D2) value. Else column D2.

In the example above, the 3rd row is the only row that is true (A3 = A2 and B3 = B2), so I'll take 246 (previous column C value) + 0 (column D value). Second row is partially true so column C value will be the same as column D.

In the sample Tableau file, I tried to use the lookup function to reference the row above, but got calculation errors. What is the syntax for the calculation above?

Any help would be appreciated

• ###### 1. Re: Table Calc - Taking value from the row above

Hi Sira,

If I understand correctly, then you were very close with the calculated field you created. A few things just needed to be added:

IF Lookup(ATTR([ID]), -1) = attr([ID]) AND Lookup(ATTR([Date]), -1) = attr([Date]) THEN previous_value(1) + sum([Amount])

ELSE sum([Amount])

END

Hope this helps!

-Tracy

• ###### 2. Re: Table Calc - Taking value from the row above

This works! Thanks Tracy

Sira