【问题标题】:Crystal Reports: How to make a report with Monthly, Quarterly, and YTD field totals?Crystal Reports:如何制作包含月度、季度和年初至今字段总计的报告?
【发布时间】:2019-11-13 22:21:39
【问题描述】:

这是我正在使用的表格的一个缩略示例:

Month ............ SiteID ........ Patients ....FundingSource.... Year
January ............ 1 ........... 13 .......... ABCD.......... 2019
February............ 1 ........... 223 ......... ABCD.......... 2019
February ........... 2 ........... 52 .......... ABCD.......... 2019
February ........... 3 ........... 21........... EFGH.......... 2018
March .............. 1 ........... 44 .......... EFGH.......... 2018
April .............. 1 ........... 12 .......... ABCD.......... 2019
May................. 1 ........... 34 .......... ABCD.......... 2018
May................. 1 ........... 51 .......... ABCD.......... 2019
June ............... 1 ............62 .......... EFGH.......... 2017

我正在尝试输出一份报告,该报告显示给定参数的每月、每季度和年初至今的患者总数。参数是 FundingSource、SiteID、Month、Year。因为报告应该看起来像一个表格,所以它必须将结果打印一次/在一页上。

编辑:季度总数应该是从 7 月到 6 月的财政季度。 Year 列是日历年。

Patients 字段本身是一个字符串字段,表示当月就诊的患者数量。因此,创建每月总计很容易,因为只需添加字段即可。

对于季度总计,我创建了一个 Cdbl 公式字段来将表格转换为一个数字(它是我们数据库中的一个 nvarchar 字段——不能在运行总计字段中求和),然后运行该字段的每个季度的总字段(通过使该 cdbl 字段评估 Month IN [January, February, March, April] 等,并在 SiteID 更改时重置)。然后我创建了另一个公式字段,该字段将输出该季度的相应运行总计字段,无论哪个月份

例如

 IF month IN [January, February, March, April] then
{#PatientsSeenQ1}

我遇到的问题是,给定这些参数字段,Quarterly 结果最终与 Monthly 结果相同,因为 Month = ?Month 并且无法缩小以捕获该季度的其他月份。我认为获取 YTD 总数也是同样的问题。

我一直在努力解决这个问题一段时间,所以任何帮助将不胜感激!这对我的工作来说是一个重要的问题,所以我一定会及时回复。

编辑:

我被要求像这样格式化输出(假设日历年季度作为示例):

Reporting Period: May 2019
Funding Source: ABCD
Site: 1

........................... Monthly ... Quarterly ..... YTD
Number of patients seen:..... 51 ........ 63........... 299

我不必针对每个站点、年份和月份进行报告,只需针对输入的站点、年份、资金来源和月份(参数)进行报告。输出应该是用户将在网站上查看的报告的可打印版本。

编辑:

通过用户 heringer 的以下内容,我能够找到解决问题的方法。对于年初至今,我有外部帮助,所以这是答案:

我创建了一个公式字段@FiscalYear 来确定年份:

IF {@RowMonthCDate} IN [7,8,9,10,11,12] and {@ParMonthCDate} IN [1,2,3,4,5,6] THEN toText((ToNumber({?Year})-1),"#")
ELSE IF {@RowMonthCDate} IN [1,2,3,4,5,6] and {@ParMonthCDate} IN [7,8,9,10,11,12] THEN toText((ToNumber({?Year})+1),"#")
ELSE toText((ToNumber({?Year})),"#")

然后对于 YTD 运行总计字段,我将其用于评估公式:

 {reporting_year} = {@FiscalYear} AND
(
     if  {@ParMonthCDate} = 7  then  {@RowMonthCDate} = 7
else if  {@ParMonthCDate} = 8  then  {@RowMonthCDate} in [7,8]
else if  {@ParMonthCDate} = 9  then  {@RowMonthCDate} in [7,8,9]
else if  {@ParMonthCDate} = 10 then  {@RowMonthCDate} in [7,8,9,10]
else if  {@ParMonthCDate} = 11 then  {@RowMonthCDate} in [7,8,9,10,11]
else if  {@ParMonthCDate} = 12 then  {@RowMonthCDate} in [7,8,9,10,11,12]

else if  {@ParMonthCDate} = 1 then {@RowMonthCDate} in [7,8,9,10,11,12,1]
else if  {@ParMonthCDate} = 2 then {@RowMonthCDate} in [7,8,9,10,11,12,1,2]
else if  {@ParMonthCDate} = 3 then {@RowMonthCDate} in [7,8,9,10,11,12,1,2,3]
else if  {@ParMonthCDate} = 4 then {@RowMonthCDate} in [7,8,9,10,11,12,1,2,3,4]
else if  {@ParMonthCDate} = 5 then {@RowMonthCDate} in [7,8,9,10,11,12,1,2,3,4,5]
else if  {@ParMonthCDate} = 6 then {@RowMonthCDate} in [7,8,9,10,11,12,1,2,3,4,5,6]
) 
AND
 {report.fundingsource} = {?FundingSource} AND
 {report.Site_id} = {?Site_ID}

也许不优雅,但它为我提供了该财政年度参数月份的字段总数。再次感谢 heringer 在这方面与我一起工作了大约一周!

【问题讨论】:

    标签: crystal-reports crystal-reports-2016


    【解决方案1】:

    您可以创建一个公式来使用年份和月份(并考虑第 1 天)构建日期。

    然后通过这个公式创建3个组。

    使用组专家对每个组进行然后每年、每季度、每月。

    然后将简单的汇总字段放在组页脚。

    我不确定它是否适合您的最终设计。如果没有,请出示。

    编辑:

    在新的 cmets 之后,这是一个新的有目的的解决方案。我将保留上面的旧版本以供进一步参考。

    基于 com cmets,我假设报告将显示一年、一个月、一个资金来源和一个站点 ID 的数据。

    我知道您的出发点是正确的。我会尽力提供细节帮助。

    1. 创建参数:{?Year}、{?Month}、{?FundingSource?}、{?SideId}。
    2. 创建运行总计字段 {#PatientsInMonth} 以求和 {Table.Patients} 并使用此公式设置“评估/使用公式”:
    {Table.Year} = {?Year} AND
    {Table.Month} = {?Month} AND
    {Table.FundingSource} = {?FundingSource} AND
    {Table.SiteId} = {?SiteId}
    1. 创建运行总计字段 {#PatientsInQuarter} 以求和 {Table.Patients} 并使用此公式设置“评估/使用公式”:
     numbervar rowNumberOfMonth := 0; //TODO 我任由你决定,因为你说你做到了
     numbervar parNumberOfMonth := 0; //去做
     numbervar rowQuarter := (rowNumberOfMonth - 1) \ 4; //注意整数除法,符号没有错
     numbervar parQuarter := (parNumberOfMonth - 1) \ 4; //注意整数除法,符号没有错
     {Table.Year} = {?Year} AND
     rowQuarter = parQuarter AND
     {Table.FundingSource} = {?FundingSource} AND
     {Table.SiteId} = {?SiteId}
    1. 创建运行总计字段 {#PatientsInYear} 以求和 {Table.Patients} 并使用此公式设置“评估/使用公式”:
     {Table.Year} = {?Year} AND
     {Table.FundingSource} = {?FundingSource} AND
     {Table.SiteId} = {?SiteId}
    1. 将运行总计字段放在报表页脚中。

    【讨论】:

    • 您好!谢谢你。我已经添加了我被要求应用于报告的最终设计:我不确定这个解决方案是否适用,因为月度、季度和年初至今都应该在同一条线上?如果没有,并且没有其他解决方案,那么我可以从那里开始,但我想知道您对这些新信息有何看法。
    • 您是否按年月、来源和站点对报告进行分组?并显示所有出现的事件?
    • 嗨!希望我理解正确:我不必为每个站点、年份和月份报告,只针对输入的站点、年份、资金来源和月份(参数)进行报告。输出应该是用户将在网站上查看的报告的可打印版本。 (我会将其添加到原始问题中)
    • 哦,伙计,将公式放入运行总计字段正是我所缺少的。对于季度字段,我确实想出了如何将月份转换为数字;但是,我应该在我的问题中澄清(我现在会这样做)季度字段是 FISCAL 季度,我们的财政年度从 7 月到 6 月 - 但是,“年”列是日历年。此外,年份总数是迄今为止的年份,所以它不能只是?年份:有没有办法在不将它们写成长格式的情况下或 if then 语句的情况下制作这些总数?我会用这个更新我的问题。
    • 我没听懂。例如,您是说 5 月的季度是 3 月、4 月、5 月和 6 月?如果是这样,只需改变两个季度的计算。例如:(6 + rowNumberOfMonth - 1) \ 4
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-16
    • 2018-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多