简体   繁体   English

交叉表 Crystal Reports 空值与零

[英]Crosstabs Crystal Reports Null value vs zero

I'm creating a crosstab report showing the survey history for gopher tortoises ( if you must know what that is ) monitoring stations.我正在创建一个交叉表报告,显示地鼠龟(如果您必须知道那是什么)监测站的调查历史。 Not all stations are monitored for a given survey and sometimes when we monitor we don't find any and thus record a 0 which is a valid result.对于给定的调查,并非所有站点都受到监控,有时当我们进行监控时,我们没有发现任何站点,因此记录为 0,这是一个有效的结果。

In the crosstab when the station isn't used I would like it to say "N/A" or some other equivalent, but when it's a zero I want it to stay as zero.在不使用站时的交叉表中,我希望它说“不适用”或其他一些等效项,但是当它为零时,我希望它保持为零。

I've found so much on how to change a null to a zero, but nothing when you want to keep the zero and somehow note the null.我已经找到了很多关于如何将空值更改为零的内容,但是当您想保留零并以某种方式注意空值时,什么也没有。

Below is what the crosstab should look like.下面是交叉表的外观。 You'll see that the 0 in Station4 on 1/1/2004 is "real" (meaning we didn't find any) but all of the N/A's are when we didn't use the station.您会看到 2004 年 1 月 1 日在 Station4 中的 0 是“真实的”(意味着我们没有找到任何),但所有 N/A 都是在我们没有使用该站时。

                          Survey Dates
|          | 1/1/2000 | 1/1/2002 | 1/1/2004 | 1/1/2006 |
|----------|----------|----------|----------|----------|
| Station1 | 9        | 5        | N/A      | N/A      |
| Station2 | 5        | 7        | 2        | 6        |
| Station3 | N/A      | N/A      | 6        | 9        |
| Station4 | 10       | 9        | 0        | 11       |

This is what the Oracle table look like for the 1/1/2000 survey as an example以 2000 年 1 月 1 日的调查为例,Oracle 表是这样的

| SurveyID | StationID | Number |
|----------|-----------|--------|
| 1        | 1         | 9      |
| 1        | 2         | 5      |
| 1        | 4         | 6      |

So, basically how to I keep the zero's and put some text in the nulls in a CR crosstab?那么,基本上如何保留零并将一些文本放入 CR 交叉表的空值中?

Thanks!谢谢!

Because CR doesn't differentiate between nulls and actual zeros in the crosstab, you can try replacing actual zero values with a placeholder so you can tell the difference.由于 CR 不区分交叉表中的空值和实际零值,您可以尝试用占位符替换实际零值,以便您可以区分。 Note that this solution will only work if you are trying to display the values and not do any aggregate calculations.请注意,此解决方案仅在您尝试显示值而不进行任何聚合计算时才有效。

First, create a formula that will replace the zeros with a placeholder value.首先,创建一个公式,用占位符值替换零。 In this case, I'm using -1 since that number should never appear in the database.在这种情况下,我使用 -1,因为该数字永远不会出现在数据库中。

    //{@Survey Num}
    local numbervar totalSurvey;
    totalSurvey:={Table.ActiveBurrows} + {Table.InactiveBurrows};
    if totalSurvey=0 then -1 else totalSurvey

Use this formula to create your crosstab.使用此公式创建交叉表。 Now you need to set a display string so that everything appears correctly.现在您需要设置一个显示字符串,以便所有内容都正确显示。 Right-click one of your crosstab cells → hit "Format Field" → select the "Common" tab → then create a "Display String" formula.右键单击一个交叉表单元格→点击“格式字段”→选择“通用”选项卡→然后创建一个“显示字符串”公式。 That formula should be something like:这个公式应该是这样的:

if currentfieldvalue=-1 then "0" else if currentfieldvalue=0 then "N/A" else totext(currentfieldvalue,0,'')

Now you're basically just printing the real values over top of the placeholders.现在您基本上只是在占位符顶部打印实际值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM