Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reporting Services - Count Column Values if equals A

I have a dataset called 'dsAllStuTargetData' - i'm trying to count the number of the 'A' values that appear in the column 'Target'.

I'm doing this using a textbox with an expression, I can count the total number of values using the following:

=Count(Fields!Target.Value, "dsAllStuTargetData")

However when I try to count where the value equals 'A' it doesn't work.

=Count(IIF(Fields!Target.Value, "dsAllStuTargetData")="A",1,0)
like image 522
dawsonz Avatar asked Sep 19 '13 11:09

dawsonz


People also ask

How do I use IIF in SSRS expression?

Using IIF Function in SSRS We are going to add a new field to the report data set to determine if the Order Year is the Max or Current Year. As shown below, the dataset properties window is opened, and the Fields tab is selected. After clicking Add, at the bottom of the list a new field is added.

How do you sum a column in SSRS?

Add Total and Subtotal to SSRS Report: Approach 2 Next, we will add the Total at the Education level. For this, goto Yearly Income Total Column (Details Total Row -> Yearly Income Column) and right-click on it and select Add Total option. Let me open the Preview tab to check the Totals at the Education level.

How do you count in SSRS?

Count Function in SSRS falls under Report Builder Functions which basically returns a count of non-null values specified by the expression in the given scope. If statement in SSRS allows a developer to control the program flow and it's outputs. It is a decision function that can be reached through expression.

How do I add totals in report Builder?

In the tablix data region body area, right-click the cell where you want to add the total. The cell must contain a numeric field. Point to Add Total, and then click Row or Column. A new row or column outside the current group is added to the data region, with a default total for the field in the cell you clicked.


1 Answers

For this case you need a Sum, not a Count, i.e. something like:

=Sum(IIf(Fields!Target.Value = "A", 1, 0), "dsAllStuTargetData")

Count will just count the number of rows; the IIf doesn't do anything there - something like CountDistinct can be affected in certain cases but this will not work here.

However, Sum will take the total of all rows which meet the IIf condition, i.e. the total of all 1 values in the DataSet, which is what you're after.

like image 73
Ian Preston Avatar answered Sep 30 '22 14:09

Ian Preston