I have an existing SSRS report that shows some overall counts on the top of the report. The report data looks like:

column1    column2
A1         true
-          true
B5         false
A1         true
-          false
C3         false

What I need is a distinct count of the items in column1, but including all the rows with the "-". So the result for this example data should be 5, counting the "A1" rows as one. The catch is that this needs to be done in an expression or some method on the report itself. I cannot change the dataset queries.

I have tried: =COUNTDISTINCT(Fields!column1.Value) but that counts the "-" rows as one.

Is it possible to add another dataset and develop a query for that one that queries the existing dataset? Not sure if that can be done.

有帮助吗?

解决方案

This works OK for me:

=CountDistinct(IIf(Fields!column1.Value = "-", Nothing, Fields!column1.Value))
  + Sum(IIf(Fields!column1.Value = "-", 1, 0))

I'm using two aggregate IIf expressions for the two cases.

The first is CountDistinct against all the non - rows, and the second is simply a count of all - rows.

Seemed to work OK with all - rows and with no - rows.

Edit after comment

If you're using this expression outside of a tablix, you may need to specify the Scope of the aggregate:

=CountDistinct(IIf(Fields!column1.Value = "-", Nothing, Fields!column1.Value), "MyDataSet")
    + Sum(IIf(Fields!column1.Value = "-", 1, 0), "MyDataSet")
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top