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)
Date Adds
TheShadraq
I have a query that runs and pulls a comprehensive look at a massive group of rows. It is currently pulling 4300 rows, and that number grows each quarter.<br />
<br />
The report is not designed to show all 4300 rows, but rather a breakdown of the data. My question is 2 parts:<br />
<br />
<strong class='bbc'>1. How do I add dates together?</strong><br />
<p class='bbc_indent' style='margin-left: 40px;'><br />
I have 2 code snippets that work great:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>Total.ave(dataSetRow["origdate"],
BirtComp.lessThan(dataSetRow["reportdate"],"2012-04-01")
*BirtComp.equalTo(dataSetRow["docstyle"],"NPR")
*BirtComp.greaterOrEqual(dataSetRow["reportdate"],"2012-01-01")
*BirtComp.equalTo(dataSetRow["orig"],"ORIG"))
Total.ave(dataSetRow["compdate"],
BirtComp.lessThan(dataSetRow["reportdate"],"2012-04-01")
*BirtComp.equalTo(dataSetRow["docstyle"],"NPR")
*BirtComp.greaterOrEqual(dataSetRow["reportdate"],"2012-01-01")
*BirtComp.equalTo(dataSetRow["comp"],"COMP"))
</pre>
The idea is to grab an average date within a range based on certain criteria. This code actually works. Separately. My question is this: If the first returns <em class='bbc'>2/1/2012</em>, and the second returns <em class='bbc'>2/15/12</em> - how can I subtract one from the other and get "14 days"...all in the same data field?<br /></p>
<strong class='bbc'>2. Is there a better place to put my code than where I am putting it? (optimization)</strong><br />
<p class='bbc_indent' style='margin-left: 40px;'><br />
In my report, I have added different <em class='bbc'>data expressions</em> from the Palette. There are something like 40 of these and inside them, the expressions have various versions of the code above. It makes the report run heavy. The query takes 2-4 seconds to run, but the calculations take quite a while.<br />
<br />
Is there a better place to put this code than where I am currently doing it?<br /></p>
<br />
I hope that makes sense, thanks for your time.<br />
<br />
-Shadraq
Find more posts tagged with
Comments
kclark
For your first question you can use BirtDateTime.diffDay() to get the number of days<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
date1 = 2/1/2012
date2 = 2/15/2012
diffDays = BirtDateTime.diffDay( date1, date2 )
</pre>
<br />
That should return 14<br />
<br />
You can quickly test this by adding a dynamic text object to your report and putting<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
BirtDateTime.diffDay( "2009-01-01", "2009-04-15" )
</pre>
<br />
In the expression builder.
TheShadraq
Thanks for the response. Yes I have used diffDay and it works as you indicated. My question more of how to combine the code I put in my initial post, together with what you suggested, into one expression that gives me "14".
TheShadraq
Ok, I did some more work and, coupled with your advice, I've worked through my first issue: <strong class='bbc'>1. How do I add dates together?</strong> <br />
<br />
In case anyone runs into this, the below code will average a group of dates based on specific parameters, find the difference between those two date sets, then round it to 2 decimal spots.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>BirtMath.round(
diffDays = BirtDateTime.diffDay(
(Total.ave(dataSetRow["origdate"],
BirtComp.lessThan(dataSetRow["reportdate"],"2012-04-01")
*BirtComp.equalTo(dataSetRow["docstyle"],"NPR")
*BirtComp.greaterOrEqual(dataSetRow["reportdate"],"2012-01-01")
*BirtComp.equalTo(dataSetRow["orig"],"ORIG"))),
(Total.ave(dataSetRow["compdate"],
BirtComp.lessThan(dataSetRow["reportdate"],"2012-04-01")
*BirtComp.equalTo(dataSetRow["docstyle"],"NPR")
*BirtComp.greaterOrEqual(dataSetRow["reportdate"],"2012-01-01")
*BirtComp.equalTo(dataSetRow["comp"],"COMP")))
),2)</pre>
<br />
Anyone have an idea on my other issue? Having this much custom code, running at about 40 spots in the report, causes this to really lag. <strong class='bbc'>2. Is there a better place to put my code than where I am putting it? (optimization)</strong>
Tubal
It's always faster to do the calculations in your query.
Where is your data coming from? Can you do the calculations before BIRT gets it?
TheShadraq
This is my query. I could probably rework it. With the calcs coming in after SQL runs, the report is massively sluggish. I'll have to give messing with the query again a shot.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>select count(DISTINCT workorder.wonum) as total, workorder.reportdate as reportdate,
(select min(a.status) from wostatus a where a.wonum = workorder.wonum AND a.siteid = workorder.siteid and a.status = 'ORIG') as 'orig',
(select min(a.changedate) from wostatus a where a.wonum = workorder.wonum AND a.siteid = workorder.siteid and a.status = 'ORIG') as 'origdate',
(select min(a.status) from wostatus a where a.wonum = workorder.wonum AND a.siteid = workorder.siteid and a.status = 'RTS') as 'rts',
(select min(a.changedate) from wostatus a where a.wonum = workorder.wonum AND a.siteid = workorder.siteid and a.status = 'RTS') as 'rtsdate',
(select min(a.status) from wostatus a where a.wonum = workorder.wonum AND a.siteid = workorder.siteid and a.status = 'RELEASED') as 'released',
(select min(a.changedate) from wostatus a where a.wonum = workorder.wonum AND a.siteid = workorder.siteid and a.status = 'RELEASED') as 'releaseddate',
case when (select min(a.status) from wostatus a where a.wonum = workorder.wonum aND a.siteid = workorder.siteid and a.status in('comp','comp-rev','COMP-WCC','Completed','CLOSE')) is not null then 'COMP' else null end as 'comp',
workorder.actfinish as 'compdate', workorder.docstyle
from workorder
INNER JOIN wostatus on (workorder.wonum = wostatus.wonum and workorder.siteid = wostatus.siteid)
WHERE workorder.siteid in ('MAINT','WATER')
AND workorder.pmnum is null
AND workorder.status in ('close','comp','comp-rev','COMP-WCC','Completed')
AND workorder.istask = '0'
AND ((wostatus.status = 'RTS' AND workorder.DOCSTYLE = 'PLAN') or (workorder.DOCSTYLE = 'NPR'))
group by workorder.wonum,workorder.reportdate,workorder.siteid,workorder.actfinish,workorder.docstyle</pre>