Home » Archived » BIRT » Balance sheet dynamic crosstab: how to sum up to date rather than between dates
Balance sheet dynamic crosstab: how to sum up to date rather than between dates [message #685152] |
Thu, 16 June 2011 19:22  |
Eclipse User |
|
|
|
i'm creating a report designed to output a crosstab balance sheet by quarter.
in other words, each quarter should display the balance of asset, liability, and equity accounts at that point. to calculate the balance, i need the sum of all previous transactions up till the end of that quarter. the "natural" outcome of creating a datacube with appropriate measures is to display the sum of all transactions during the period -- which is great for income statement, but not balance.
does anyone have experience with this issue? what's the best way to resolve?
thanks!
.brush
|
|
| | | |
Re: Balance sheet dynamic crosstab: how to sum up to date rather than between dates [message #685673 is a reply to message #685435] |
Fri, 17 June 2011 23:58   |
Eclipse User |
|
|
|
and jason,
i'd love to try your solution too, but unfortunately the file you pasted into the message was cut short, and can't be opened. can you attach the file? or describe/copy just the script itself?
UPDATE:
i think this may be the report you're referring to, on the birt-exchange: um, i haven't posted 5 msgs, so google for birt-creating-your-own-running-sum-in-a-crosstab on the birt-exchange, and see attached.
however, i have two just one follow-up question.
1) when i created a :Text: object with the same cell content in the detail of the crosstab as the one in the demo file, it didn't run but rather simply printed the text (rather as i would expect). when i copied the entire cell, it executed (with errors). what is being set so that the code in the text is executed?
2) i slightly edited the content of the file to the following. it outputs null. any ideas why?
UPDATE
ok, figured it out. in a data cube, you need to refer to rows by their measure["xx"] or dimension["firstlevel"]["secondlevel"] etc. names. works now! thanks! still curious about the above...
<VALUE-OF>if (reportContext.getPersistentGlobalVariable("runningbalance") == null){
if (row["amount"] == null){
temp = 0;
}
else{
temp = row["amount"];
reportContext.setPersistentGlobalVariable("runningbalance", temp.toString());
}
}
else{
temp = parseInt(reportContext.getPersistentGlobalVariable("runningbalance")) + row["amount"]
reportContext.setPersistentGlobalVariable("runningbalance", temp.toString());
}
temp;</VALUE-OF>
thanks a ton!
.b
[Updated on: Sat, 18 June 2011 01:52] by Moderator
|
|
| |
Re: Balance sheet dynamic crosstab: how to sum up to date rather than between dates [message #686238 is a reply to message #686082] |
Tue, 21 June 2011 17:43   |
Eclipse User |
|
|
|
thanks, jason, for the suggestions on how to do similar thing in script.
i actually figured out the specific answer to my question above: if a text field has content type "HTML" then <value-of> script will get executed, near as i can tell.
(i also upgraded postgresql to 8.4 and tried the windowing functions, which are clearly powerful but resulted in some peculiar behavior when trying to group resulting data ... more perhaps in another post.)
so i've been working with the <value-of> text box, which results in printable crosstab with accurate data (oh, one comment: i found the script as written was often dropping the final iteration of the sum, so i output the actual global variable rather than temp, and it seems to work correctly).
however, i've been having major headaches trying to display this data as a chart. what is the best way (*is* there a way) to access scripted data content from a crosstab or table in a chart?
i ended up creating non-crosstab tables with the data presented vertically, which would then be hidden, in order to essentially redo the whole thing in the chart using runningsum over the groups. however, i've had significant challenges with getting the data to present accurately what's in the tables when there are multiple series groupings and the only data i want to chart is the aggregate-over-group runningsum, not the detail. ... more on this separately, perhaps.
but that's a specific question: how can we best access javascripted data in a chart?
thanks!
.b
|
|
| | |
Re: Balance sheet dynamic crosstab: how to sum up to date rather than between dates [message #687609 is a reply to message #687606] |
Wed, 22 June 2011 16:36   |
Eclipse User |
|
|
|
by the way, for those interested in the windowing sql approach, here's the challenge i'm currently stuck on: i finally got the SQL to calculate balances correctly, but it only produces a value in any given quarter if there's at least one transaction in that quarter. this is a problem: with a "running balance" any activity in a previous period should result in a value being printed, even if unchanged from the previous quarter.
i was looking at trying to come up with a subselect that would let me do an outer join that would force an entry for every quarter-account combo, but haven't quite figured it out. ideas?
here's the sql i'm currently working with (for ledger-smb data structure):
select c.accno, date_trunc('quarter', ac.transdate) as quarter,
sum(ac.amount) as qtot,
sum(sum(ac.amount)) over (partition by accno order by date_trunc('quarter', ac.transdate)) as balance
from chart c
left join acc_trans ac on (c.id = ac.chart_id)
group by c.accno, date_trunc('quarter', ac.transdate);
the left (outer) join forces there to be one entry for every account in the chart -- but i need one entry per account PER QUARTER. ideas?
[Updated on: Wed, 22 June 2011 16:38] by Moderator
|
|
| |
Re: Balance sheet dynamic crosstab: how to sum up to date rather than between dates [message #687756 is a reply to message #687609] |
Thu, 23 June 2011 02:53   |
Eclipse User |
|
|
|
Hi,
try the following sql:
with
-- GENERATE SOME RANDOM DATA --
chart as (
select 1 id, 12345 accno union all
select 2 id, 23456 accno union all
select 3 id, 34567 accno)
,
acc_trans as (
select '2010-01-01'::date transdate, 100.0 amount, 1 chart_id union all
select '2010-04-01'::date transdate, 100.0 amount, 1 chart_id union all
select '2010-10-01'::date transdate, 100.0 amount, 1 chart_id union all
select '2010-10-01'::date transdate, 100.0 amount, 2 chart_id union all
select '2010-01-01'::date transdate, 100.0 amount, 2 chart_id union all
select '2010-10-01'::date transdate, 100.0 amount, 3 chart_id)
-- CALCULATE OUTPUT
-- 1) aggregate transactions
,
trans_aggregation as (
select
c.accno,
c.id,
date_trunc('quarter', ac.transdate) as granularity,
sum(ac.amount) as qtot
from
chart c
left join acc_trans ac on (c.id = ac.chart_id)
group by
c.accno,
date_trunc('quarter', ac.transdate),
c.id
)
-- 2) calculate running sum
select
d.granularity,
d.id,
coalesce(sum(qtot) over (partition by d.id order by granularity rows between unbounded preceding and current row),0.0) as qtot
from
(select
*
from
(SELECT generate_series('2010-01-01'::date::timestamp with time zone, Now()::date::timestamp with time zone, '3 months '::interval)::date AS granularity) a , -- generate quarters
(select id from chart) b -- and create product with account id
) d
left join trans_aggregation using (granularity, id)
Tomas
|
|
| |
Re: Balance sheet dynamic crosstab: how to sum up to date rather than between dates [message #709644 is a reply to message #685673] |
Thu, 04 August 2011 02:06   |
Eclipse User |
|
|
|
HI Jason,
<VALUE-OF>if (reportContext.getPersistentGlobalVariable("runningbalance") == null){
if (row["amount"] == null){
temp = 0;
}
else{
temp = row["amount"];
reportContext.setPersistentGlobalVariable("runningbalance", temp.toString());
}
}
else{
temp = parseInt(reportContext.getPersistentGlobalVariable("runningbalance")) + row["amount"]
reportContext.setPersistentGlobalVariable("runningbalance", temp.toString());
}
temp;</VALUE-OF>
This code is working for running sum.
I am getting both row and column wise running sum,
I want row wise running sum.
My cross tab is like,
Project Name || Revenue || Jan || Feb || Mar || Apr
A ||||||||||| J1 ||||||| 0 || 1 || 3 || 0
A ||||||||||| J2 ||||||| 10 || 11 || 3 || 0
B ||||||||||| J1 ||||||| 0 || 1 || 3 || 0
B ||||||||||| J2 ||||||| 10 || 11 || 3 || 0
From the above table, The revenue will be changing always,
From the script, the output is NOT correct for 2 revenues
I want the output like, running sum
A ||||||||||| J1 ||||||| 0 || 1 || 4 || 4
A ||||||||||| J2 ||||||| 10 || 21 || 24 || 24
B ||||||||||| J1 ||||||| 0 || 1 || 4 || 4
B ||||||||||| J2 ||||||| 10 || 21 || 24 || 24
Can you please help me on this.
Thanks,
Jeyinul.
[Updated on: Thu, 04 August 2011 08:02] by Moderator
|
|
|
Re: Balance sheet dynamic crosstab: how to sum up to date rather than between dates [message #709997 is a reply to message #709644] |
Thu, 04 August 2011 11:06   |
Eclipse User |
|
|
|
I am not certain what you mean by the script is correct for 2 revenues.
If you use a script similar to the one I posted previously you can reset
it on the Revenue label field oncreate. For example in you xtab reset
it on the onCreate script for the label that produces J1, J2.
Jason
On 8/4/2011 2:06 AM, jeyinul wrote:
> HI Jason,
>
> <VALUE-OF>if
> (reportContext.getPersistentGlobalVariable("runningbalance") == null){
> if (row["amount"] == null){
> temp = 0;
> }
> else{
> temp = row["amount"];
> reportContext.setPersistentGlobalVariable("runningbalance",
> temp.toString());
> }
> }
> else{
> temp =
> parseInt(reportContext.getPersistentGlobalVariable("runningbalance")) +
> row["amount"]
> reportContext.setPersistentGlobalVariable("runningbalance",
> temp.toString());
> }
> temp;</VALUE-OF>
>
>
> This code is working for running sum.
>
> I have one doubt,
>
> My cross tab is like,
>
> Project Name || Revenue || Jan || Feb || Mar || Apr
> A ||||||||||| J1 ||||||| 0 || 1 || 3 || 0
> A ||||||||||| J2 ||||||| 10 || 11 || 3 || 0
>
> B ||||||||||| J1 ||||||| 0 || 1 || 3 || 0
> B ||||||||||| J2 ||||||| 10 || 11 || 3 || 0
>
> From the above table, The revenue will be changing always,
>
> From the script, the output is correct for 2 revenues
>
> I want the output like, running sum
>
> A ||||||||||| J1 ||||||| 0 || 1 || 4 || 4
> A ||||||||||| J2 ||||||| 10 || 21 || 24 || 24
>
> B ||||||||||| J1 ||||||| 0 || 1 || 3 || 0
> B ||||||||||| J2 ||||||| 10 || 21 || 24 || 24
>
>
> Can you please help me on this.
>
> Thanks,
> Jeyinul.
>
>
|
|
| | | | | | | | | | | | |
Goto Forum:
Current Time: Tue Jul 01 14:28:06 EDT 2025
Powered by FUDForum. Page generated in 0.08520 seconds
|