【问题标题】:Report builder 3.0 count with where clauseReport builder 3.0 count with where 子句
【发布时间】:2014-09-05 12:50:24
【问题描述】:

对于我们的一份报告,我试图获取列 Canceled 值为 1 的行数。过去,我使用在 Stackoverflow 上找到的解决方案将 Sum 函数与 IIF 一起使用,即

=Sum(iif(Fields!Canceled.Value="True", 1, 0))

但是现在我的源数据对于一个 booking_id 有多行,所以我需要在该列上添加一个不同的。在 SQL 中我可以轻松做到

SELECT COUNT(DISTINCT(booking_id)) FROM Booking WHERE Canceled=1

但我不知道如何在 Report Builder 3.0 中获得相同的行为。有什么想法吗?

【问题讨论】:

  • 我不确定您是否可以在报告中执行此操作。我会用 SQL 来做。
  • 如果数据源是 sql 查询,我同意 Tab - 只需在 sql 中执行 - 如果您需要帮助或不使用查询作为数据源,请告诉我们

标签: reporting-services report builder reportbuilder3.0


【解决方案1】:

如果可能,按照 cmets 中的建议在 T-SQL 中执行此操作不是一个坏主意,但您可以在报告中使用如下表达式执行此操作:

=CountDistinct(IIf(Fields!Canceled.Value = 1, Fields!booking_id.Value, Nothing))

CountDistinct 将忽略 Nothing(即 Null)记录,因此您可以将 CountDistinct 应用于基于 Canceled 返回 booking_idNothingIIf 表达式。

【讨论】:

  • @Sander,这有帮助吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-02-08
  • 2013-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-16
  • 2019-12-23
相关资源
最近更新 更多