Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Calculate from Previous Row?
cornett
How do you make a calculation from previous returned rows in a table? I am trying to calculate a daily total by subtracting the previous day's overall total from the current day's overall total.
Example:
Date GrandTotal DailyTotal
Mon A
Tues B B-A
Wed C C-B
Thurs D D-C
Fri E E-D
etc.
Find more posts tagged with
Comments
johnw
Easiest way, create a computed column in your data set, and use the following expression:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
var lastValueToReturn = -1;
if (reportContext.getGlobalVariable("lastValue") != null)
{
lastValueToReturn = reportContext.getGlobalVariable("lastValue");
}
reportContext.setGlobalVariable("lastValue", row["whateverMyCurrentValueIs"]);
lastValueToReturn;
</pre>
cornett
Ahh, good work! It is working almost perfectly. Now the only thing left is how to get an accurate reading for the first day of the month. I guess I'd have to modify my SQL query somehow to contain that day's information? Any ideas on how to do that? Thanks again for the help!
hessasm
<p>thanks you ,</p>
<p>that's possible in cross table ? </p>
JFreeman
<p>The general logic should be applicable to a crosstab as well.</p>
<p> </p>
<p>As this is a very old thread, please create a new topic for any additional questions.</p>