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)
Average based on month
navee4
Hi,
I am wondering if someone can help me with avg function. Right now BIRT avg formula works out avg as below
example
5+5+5/3 = 5
I want to behave avg formula like below
5+5+5/31(number of days in month) = .48
I am attaching my template also.
Thanks in advance.
Find more posts tagged with
Comments
johnw
Its pretty simple. What you can do is define a global function in the reports initialize event to get the max days in a given month using a GregorianCalendar. In my example, the function will just accept the current date/time as the basis to get the month. It would look like this:
initialize:
function getDaysInMonth()
{
var calendar = new Packages.java.util.GregorianCalendar();
calendar.setTime(new java.util.Date());
return calendar.getActualMaximum(Packages.java.util.GregorianCalendar.DAY_OF_MONTH);
}
Then, you drop your table into your report, and use a Sum aggregation on the field you want. Then, you can drop a dynamic text or data element into the table with an expression of (sumOfField / getDaysInMonth()).
See the attached report as an example.
navee4
Thanks JohnW