Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
ysiroong
Contributor III
Contributor III

Chart (Pivot or Straight table) Calculations using prior row

<body><p>I need to create a straight table with 1 dimension and 2 expressions (a and b), 1 of which relies on the results of the previous row.  The second expression would be previous(b) + a.  Is there a way to do this? </p> <p>Example below</p> <p><col span="3" width="64"></col> <tr height="17"> <td width="64" height="17"> <table width="192" cellpadding="0" cellspacing="0" border="0"> <tbody> <tr> <td valign="bottom" width="64"> <p>dimen</p> </td> <td valign="bottom" width="64"> <p>a</p> </td> <td valign="bottom" width="64"> <p>b</p> </td> </tr> <tr> <td valign="bottom" width="64"> <p align="right">1</p> </td> <td valign="bottom" width="64"> <p align="right">5</p> </td> <td valign="bottom" width="64"> <p align="right">20</p> </td> </tr> <tr> <td valign="bottom" width="64"> <p align="right">2</p> </td> <td valign="bottom" width="64"> <p align="right">2</p> </td> <td x:fmla="=C2+B3" valign="bottom" width="64"> <p align="right">22</p> </td> </tr> <tr> <td valign="bottom" width="64"> <p align="right">3</p> </td> <td valign="bottom" width="64"> <p align="right">12</p> </td> <td x:fmla="=C3+B4" valign="bottom" width="64"> <p align="right">34</p> </td> </tr> <tr> <td valign="bottom" width="64"> <p align="right">4</p> </td> <td valign="bottom" width="64"> <p align="right">6</p> </td> <td x:fmla="=C4+B5" valign="bottom" width="64"> <p align="right">40</p> </td> </tr> <tr> <td valign="bottom" width="64"> <p align="right">5</p> </td> <td valign="bottom" width="64"> <p align="right">4</p> </td> <td x:fmla="=C5+B6" valign="bottom" width="64"> <p align="right">44</p> </td> </tr> <tr> <td valign="bottom" width="64"> <p align="right">6</p> </td> <td valign="bottom" width="64"> <p align="right">5</p> </td> <td x:fmla="=C6+B7" valign="bottom" width="64"> <p align="right">49</p> </td> </tr> <tr> <td valign="bottom" width="64"> <p align="right">7</p> </td> <td valign="bottom" width="64"> <p align="right">5</p> </td> <td x:fmla="=C7+B8" valign="bottom" width="64"> <p align="right">54</p> </td> </tr> <tr> <td valign="bottom" width="64"> <p align="right">8</p> </td> <td valign="bottom" width="64"> <p align="right">9</p> </td> <td x:fmla="=C8+B9" valign="bottom" width="64"> <p align="right">63</p> </td> </tr> <tr> <td valign="bottom" width="64"> <p align="right">9</p> </td> <td valign="bottom" width="64"> <p align="right">7</p> </td> <td x:fmla="=C9+B10" valign="bottom" width="64"> <p align="right">70</p> </td> </tr> <tr> <td valign="bottom" width="64"> <p align="right">10</p> </td> <td valign="bottom" width="64"> <p align="right">7</p> </td> <td x:fmla="=C10+B11" valign="bottom" width="64"> <p align="right">77</p> </td> </tr> </tbody> </table> <br /></td> <td width="64"><br /></td> <td width="64"><br /></td> </tr> </p> <p> </p> <p> </p></body>

1 Solution

Accepted Solutions
Not applicable

Try this:

=Above(B) + A


Note that the above function will return a NULL value on the first row, so you might want to incorporate protection against that:

=IF(RowNo()=1 , A , Above(B)+A )


I haven't tried this, but it should work I think,

View solution in original post

7 Replies
Not applicable

Try this:

=Above(B) + A


Note that the above function will return a NULL value on the first row, so you might want to incorporate protection against that:

=IF(RowNo()=1 , A , Above(B)+A )


I haven't tried this, but it should work I think,

ysiroong
Contributor III
Contributor III
Author

Doesn't seem to be working. I used this formula:

Sum(If(dimension= 1, x, Above(b))) + a

and get null through out. when I remove the above(b) section from the formula the first row gets calculated while the rest of the rows = a.

dimen

a

b

1

5

20

2

2

2

3

12

12

4

6

6

5

4

4

6

5

5

7

5

5

8

9

9

9

7

7

10

7

7



Not applicable

Hi

Not sure why you used Dimension=1 rather than RowNo()=1 (if you change the sort order of the table this won't work) and also, your dimension is called dimen not dimension.

See attached, pretty sure this is doing what you want.

ysiroong
Contributor III
Contributor III
Author

The dimension/expression names are irrelevant to the formula. They're just place holders. I used RowNo() = 1 at first and still ended up with the same result.

I chose to use dimension = 1 because there are more than 1 dimension in my actual formula so it actually looks more like

dim1 dim2

1 1

1 2

1 3

1 4

2 1

2 2

2 3

2 4

And my query would be if (dim2 = 1, x, above())

Not applicable

OK, try the attached, the table at the bottom in the middle should be what your looking for.

ysiroong
Contributor III
Contributor III
Author

<body><p>I just looked at the qvw you sent and the results aren&#39;t what I need. </p> <p>If I start with x = 15, the very first row would be B = x + A = 20, then starting at the second row I need the prior B + A so the results would be  20 + 2, then the third row would be 22 + 12, etc. </p> <p><col width="98"></col> <col width="98"></col> <col width="98"></col> <tr> <td height="17" class="xl22" width="98"> <table width="296" cellpadding="0" cellspacing="0" border="0"> <tbody> <tr> <td valign="bottom" width="99"> <p><strong>Dimen</strong></p> </td> <td valign="bottom" width="99"> <p><strong>sum(a)</strong></p> </td> <td valign="bottom" width="99"> <p><strong>Results</strong></p> </td> </tr> <tr> <td valign="bottom" width="99"> <p align="right">1</p> </td> <td valign="bottom" width="99"> <p align="right">5</p> </td> <td valign="bottom" width="99"> <p align="right">20</p> </td> </tr> <tr> <td valign="bottom" width="99"> <p align="right">2</p> </td> <td valign="bottom" width="99"> <p align="right">2</p> </td> <td valign="bottom" width="99"> <p align="right">22</p> </td> </tr> <tr> <td valign="bottom" width="99"> <p align="right">3</p> </td> <td valign="bottom" width="99"> <p align="right">12</p> </td> <td valign="bottom" width="99"> <p align="right">34</p> </td> </tr> <tr> <td valign="bottom" width="99"> <p align="right">4</p> </td> <td valign="bottom" width="99"> <p align="right">6</p> </td> <td valign="bottom" width="99"> <p align="right">40</p> </td> </tr> <tr> <td valign="bottom" width="99"> <p align="right">5</p> </td> <td valign="bottom" width="99"> <p align="right">4</p> </td> <td valign="bottom" width="99"> <p align="right">44</p> </td> </tr> <tr> <td valign="bottom" width="99"> <p align="right">6</p> </td> <td valign="bottom" width="99"> <p align="right">5</p> </td> <td valign="bottom" width="99"> <p align="right">49</p> </td> </tr> <tr> <td valign="bottom" width="99"> <p align="right">7</p> </td> <td valign="bottom" width="99"> <p align="right">5</p> </td> <td valign="bottom" width="99"> <p align="right">54</p> </td> </tr> <tr> <td valign="bottom" width="99"> <p align="right">8</p> </td> <td valign="bottom" width="99"> <p align="right">9</p> </td> <td valign="bottom" width="99"> <p align="right">63</p> </td> </tr> <tr> <td valign="bottom" width="99"> <p align="right">9</p> </td> <td valign="bottom" width="99"> <p align="right">7</p> </td> <td valign="bottom" width="99"> <p align="right">70</p> </td> </tr> <tr> <td valign="bottom" width="99"> <p align="right">10</p> </td> <td valign="bottom" width="99"> <p align="right">7</p> </td> <td valign="bottom" width="99"> <p align="right">77</p> </td> </tr> </tbody> </table> <br /></td> <td class="xl22" width="98"><br /></td> <td class="xl22" width="98"><br /></td> </tr> </p> <p> </p> <p> </p> <p> </p></body>

ysiroong
Contributor III
Contributor III
Author

Actually, I just played around with the formula a bit and found what I did wrong. It should have been If(dim2 = 1, Sum(X), Above(Beer)) + Sum(A), whereas I put the Sum before the If.

Thanks for the help!