我有一份按年龄和性别划分的人口统计报告。当我遇到没有女性员工的部门时,我的一个字段返回#Error。我已经尝试了我能想到的一切来避免这种情况,但还没有找到解决方案。
伪逻辑是,如果女性员工的数量 = 0,则返回“N/A”,否则给我该部门女性员工的平均年龄。我也尝试过返回零或空格。当计数为零时,所有努力都会返回#Error。
我最近的尝试如下:
=iif(sum(iif(Fields!CustGender.Value = "F",1D,0D),"ReportDataset") = 0D,"N/A",Int(Avg(IIF(Fields!CustGender.Value = "F", CDec(Fields!Age.Value),Nothing),"ReportDataset")))
=iif(sum(iif(Fields!CustGender.Value = "F",1,0),"ReportDataset") = 0,"N/A",Int(Avg(IIF(Fields!CustGender.Value = "F", CDec(Fields!Age.Value),Nothing),"ReportDataset")))
=iif(sum(iif(Fields!CustGender.Value = "F",1D,0D),"ReportDataset") = 0D," ",Int(Avg(IIF(Fields!CustGender.Value = "F", CDec(Fields!Age.Value),Nothing),"ReportDataset")))
=iif(sum(iif(Fields!CustGender.Value = "F",1,0),"ReportDataset") = 0," ",Int(Avg(IIF(Fields!CustGender.Value = "F", CDec(Fields!Age.Value),Nothing),"ReportDataset")))
新的消息:
将“Nothing”更改为 0D,错误消失,但计算不正确,因为我在我的 Avg 计算中添加了一堆零值,因此 37 岁的平均年龄变为 10 或类似的东西。
=iif(sum(iif(Fields!CustGender.Value = "F",1D,0D),"ReportDataset") = 0D,"N/A",Int(Avg(IIF(Fields!CustGender.Value = "F", CDec(Fields!Age.Value),Nothing),"ReportDataset"))) -- Fails
=iif(sum(iif(Fields!CustGender.Value = "F",1D,0D),"ReportDataset") = 0D,"N/A",Int(Avg(IIF(Fields!CustGender.Value = "F", CDec(Fields!Age.Value),0D),"ReportDataset"))) -- Works
伊恩的数据:
这是部门 05 of 26。第五个字段是性别,最后一个字段是我想要平均的年龄。
1142 B Bellingham WA M 05 - Business Services 1948-03-06 00:00:00.000 65
2620 A Ferndale WA F 05 - Business Services 1955-02-28 00:00:00.000 58
2626 A Bellingham WA M 05 - Business Services 1948-04-09 00:00:00.000 65
3164 A Bellingham WA M 05 - Business Services 1955-01-07 00:00:00.000 58
3376 A Bellingham WA F 05 - Business Services 1960-04-02 00:00:00.000 53
3867 A Maple Falls WA F 05 - Business Services 1958-06-11 00:00:00.000 55
4294 A Blaine WA F 05 - Business Services 1981-08-09 00:00:00.000 32
4580 A Bellingham WA M 05 - Business Services 1956-02-04 00:00:00.000 57
4702 A Bellingham WA M 05 - Business Services 1967-12-30 00:00:00.000 45
4709 A Lynden WA M 05 - Business Services 1961-04-27 00:00:00.000 52
4764 A Blaine WA F 05 - Business Services 1957-04-28 00:00:00.000 56
4892 A Ferndale WA F 05 - Business Services 1976-10-19 00:00:00.000 36
4971 A Bellingham WA F 05 - Business Services 1983-10-16 00:00:00.000 29
4986 C Bellingham WA M 05 - Business Services 1974-03-31 00:00:00.000 39
5085 A Bellingham WA F 05 - Business Services 1994-10-18 00:00:00.000 18
5094 A Bellingham WA F 05 - Business Services 1986-04-22 00:00:00.000 27