交叉表列间计算

在Jasper报表中,用户希望在交叉表中计算年度增长率,但发现只能得到总和。解决方案是通过SPL脚本预先计算增长率,然后在Jasper中调用。SPL脚本可以按项分组并计算增长率,如'Book'的增长率为91.42%,'Pencil'为-10.71%。Jasper可以通过JDBC连接集算器来调用这个脚本。
摘要由CSDN通过智能技术生成

【问题】

Hi I am new in this and  i would like to ask how to produce annual Growth rate using crosstab?

to make it simple ,in my database it contains the Year, Item,quantity like this:

YEARITEMQUANTITY
2014Book 35
2014Pencil56
2015Book67
2015Pencil50

now in my report query i filtered it by “YEAR”. By creating crosstab i produced something like this:

$F{Year}Total Quantity Measure
$F{Item}$V{Quantity_measure}$V{Quantity_measure}

which shows something like this

20142015Total
Book3567102
Pencil5650106

I want to calculate the annual growth rate but cant manipulate the datas by Year as it only produces the total of both years, is there any way i can use the formula for annual growth rate in crosstab?

Can anyone give me a sample template or any info on how to do it? Thank you very much. I want to produce a report output like this:

20142015Growth Rate
Book356791.42%
Pencil5650-10.71%

【回答】

这个问题需要对交叉表进行列间计算,但用 Jasper 脚本实现起来有一定难度,建议用 SPL 先计算出增长率:

A
1=mydb.query(“select * from store order by item,year”)
2=A1.group(ITEM).run(A1.record([“Growth Rate”,ITEM, ~(2).QUANTITY/ ~(1).QUANTITY-1]))

A1:查询数据并以 item 和 year 字段排序

A2:以 item 字段进行分组,计算出增长率加入序表中

Jasper 可以通过 JDBC 连接集算器,调用脚本方法和调用存储过程一样,详情参考【JasperReport 调用 SPL 脚本】。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值