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)
On Dataset with conditional averages
Macamba
Still rather confused on what to do to get something in Birt. <br />
<br />
I have a Dataset containing of the following rows:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
system_name end_month priority mtrs_minutes
System1 8 Prio1 30239
...
SystemN 9 Prio4 1800
</pre>
<br />
I plan to add average columns for "Prio 1 in a month for a system". In the end I want to get a table like:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
[Systemi]
Aug Jul Jun May Apr Mar Feb Jan Dec ...
Prio1 1:33 1:59 2:13 ..
Prio2 3:16 7:09 ... [Prio2Month4]
</pre>
<br />
In the reportContext I defined an array containing the names of the month. These names I want to get in the header row of the table. <br />
<pre class='_prettyXprint _lang-auto _linenums:0'>reportContext
function getMonth(i) {
return month [i];
}
</pre>
<br />
The second cell in the header row is defined as a label. What script should I use in the onPrepare of this element so I get the required month (Aug)?<br />
<br />
TIA
Find more posts tagged with
Comments
thuston
Use a Data control to create a binding "curDate" with expression BirtDateTime.now().
Just format the control as MMM.
Now you can make additional bindings relative to "curDate", "curplus[1-11]" = BirtDateTime.addMonth(row["curDate"],1)
Macamba
Thanks for the reply. The code I had planned to use was:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
reportContext
var months =new Array("jan", "feb", "mrc", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec");
var month = new Array(12);
var theMonth = BirtDateTime.month(BirtDateTime.today());
for (i = 0; i<= 11; i++) {
theMonth -= i;
if (theMonth <= 0)
theMonth = 11;
month [i] = months[theMonth];
}
function getMonth(i) {
return month [i];
}</pre>
<br />
Your solution (as far as I can see) uses default functionality of Birt. At the same time, I still have no answer for my (trivial?) question.<br />
<br />
After a <br />
<pre class='_prettyXprint _lang-auto _linenums:0'>this.text = "Macamba Rules!"</pre>
I get the expected self kick (e.g. <strong class='bbc'>Macamba rules!</strong>) on screen. But when I try<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>this.text = reportContext.getGlobalVariable(getMonth(0))</pre>
I get nothing. Hence my question "What script should I use in the onPrepare of this element so I get the required month (Aug)?"
Macamba
I got the required result by entering the following formula in the aggregation builder
Column binding name: Month01
Display name: Month01
Data type: Date Time
Function: FIRST (as I did not know what to fill in)
Expression: BirtDateTime.addMonth(BirtDateTime.now(), -1)
For the second column I filled in Month02 and BirtDateTime.addMonth(BirtDateTime.now(), -2) (you get the my drift).
So thanks for that solution.
But I still have the problem I am not able to get a global variable in the script of an element.