我正在使用Crystal Reports 2011并且有一个交叉表,它按YEAR(行)和MONTH(列)显示数据。我需要在任何给定的时间报告3年的数据,但在4月份,我需要放弃较旧的一年才能获得新的一年。
例如,目前我们正处于二月份,我正在报告2010年,2011年和2012年。一旦发布4月1日,我将报告2011年,2012年和2013年。因此,我将在2010年报告并在2013年报告中获取报告。我希望自动执行此操作,以便报告自动更改报告的年份。
我已尝试过各种唱片选择公式,但未能确定一个能够返回所需年份的公式。这些年份目前是手动调整的。每年4月1日,我手动调整报告,使其在3年前下降并开始包括当前年度数据。
我正在寻找有关如何解决这个问题的建议。感谢帮助!
答案 0 :(得分:1)
我认为我在评论中错误地说明了相应的日期范围,但如果我理解正确,我们需要公式来执行以下操作:
为此,我提出了以下公式字段:
创建名为DateRangeFrom
的公式字段。它应该包含:
IF datepart("m", CurrentDate) < 4 THEN
// Show three years back if we are in the months January - March DateSerial (Year(DateAdd("yyyy", -3, CurrentDate)), 1, 1) ELSE // Show two years back if we are in the months of April - December DateSerial (Year(DateAdd("yyyy", -2, CurrentDate)), 1, 1)
创建另一个名为DateRangeTo
的公式。它应该包含:
IF datepart("m", CurrentDate) < 4 THEN
// Show one year back if we are in the months January - March DateSerial (Year(DateAdd("yyyy", -1, CurrentDate)), 12, 31) ELSE // Show up to the current date if we are in the months of April - December CurrentDate
然后,您可以在记录选择公式中使用这些字段,如下所示:
{YourTable.YourDateColumn} > {@DateRangeFrom} AND {YourTable.YourDateColumn} <= {@DateRangeTo}
修改强>
如果您只想按年份搜索,请移除DateSerial
功能,并将记录选择公式更改为使用>=
代替>
,您应该留下:
创建名为DateRangeFrom
的公式字段。它应该包含:
IF datepart("m", CurrentDate) < 4 THEN
// Show three years back if we are in the months January - March Year(DateAdd("yyyy", -3, CurrentDate)) ELSE // Show two years back if we are in the months of April - December Year(DateAdd("yyyy", -2, CurrentDate))
创建另一个名为DateRangeTo
的公式。它应该包含:
IF datepart("m", CurrentDate) < 4 THEN
// Show one year back if we are in the months January - March Year(DateAdd("yyyy", -1, CurrentDate)) ELSE // Show up to the current date if we are in the months of April - December Year(CurrentDate)
然后,您可以在记录选择公式中使用这些字段,如下所示:
{YourTable.YourDateColumn} >= {@DateRangeFrom} AND {YourTable.YourDateColumn} <= {@DateRangeTo}