I want to write a where clause that counts client ids where the sequence field is equal to 1. So in SQL it would be;
Count(clientid) WHERE sequence = 1.
But how do i write this in SSRS? I tried the following but it didn't work;
=Count(IIF(Fields!Sequence.Value = 1, Fields!ClientID.Value, 0))
Any idea where I am going wrong?
Thanks in advance
Looks like you might be able to get what you want with a fairly simple adjustment. Currently, you are using the COUNT function which I assume is simply counting each result that is generated. What you want is the SUM function. Try the following expression:
=SUM(IIF(Fields!Sequence.Value = 1, 1, 0))
Related
I am trying to count the number of packages which belong to the Area by using the count. Every Area has different number of Packages.
How can I use Count here and check how many packages for a specific Area.
Also there is a attribute called 'Delivered' with defined values as D,N,P.
I want to check and calculate how much percentage of packages are in state 'D'.
Can anyone help.
I tried using the count but no luck.
=Count(Fields!Delivered.Value = 'D')
To get a count of specific records you can use something like this.
= SUM(Fields!Area.Value = "abc", 1, 0)
To get a percentage of the Delivered field do something like
=Sum(IIF(Fields!Delivered.Value = 1, 1, 0), "DataSet1")
/ Count(Fields!Delivered.Value , "DataSet1")
Make sure you change DataSet1 to match the dataset that the Delivered field comes form (you must include the quotes)
I am trying to sum two same fields, from two different Tablix's.
Both Tablix's filter for different building names. "Mydata" is the name of my dataset.
=Sum(Fields!TotalFloorArea.Value,"Mydata") +Sum(Fields!TotalFloorArea.Value, "Mydata")
How do I reference the different Tablix?
Many thanks in advance.
There is more than one way to accomplish this. One approach is to use an IIf() as part of each of your SUM() calls. Using the IIf() condition(s) you will be repeating the condition(s) used to filter your two Tablix controls.
Try something like this:
=Sum(IIf(Fields!BuildingName.Value = "BLDG-A",
Fields!TotalFloorArea.Value,
0), "Mydata") +
Sum(IIf( Fields!BuildingName.Value = "BLDG-B",
Fields!TotalFloorArea.Value,
0), "Mydata")
I prefer to use Report Variables for this. Define a couple of report variables totalBuildingA and totalBuidlingB and use the expressions above for the individual variable's expressions:
totalBuildingA
=Sum(IIf(Fields!BuildingName.Value = "BLDG-A",
Fields!TotalFloorArea.Value,
0), "Mydata")
totalBuildingB
=Sum(IIf(Fields!BuildingName.Value = "BLDG-B",
Fields!TotalFloorArea.Value,
0), "Mydata")
Then you can add the two report variables together to get the equivalent result as the first example, (but with code that is a lot more flexibile for combining the SUMs for two or more other Building Names etc):
=Variables!totalBuildingA.Value + Variables!totalBuildingB.Value
I got this to work now. I added a row Outside the group below then added Totals into Rows. Then for grand total I referenced the textboxes for example Reportitems!Textbox22 + Reportitems!Textbox23.
I'm not sure this makes sense. But now working! Just trying to work out the final formulas.
Referring to textboxes can get messy. And there's no direct way to reference sums from other groups or tables. A good option that will work for this is to add calculated fields to your dataset. You can have one for the 1 building value and another for the other 25 buildings. The expression would look something like this:
=IIf(Fields!BuildingName.Value = "BLDG-A", Fields!TotalFloorArea.Value, Nothing)
That way you can sum those calculated fields from anywhere in the report. You don't need to specify the scope in your Sum function, let it use the current scope for the cell like this:
=Sum(Fields!BldgA_TotalFloorArea.Value)
For one of our reports I'm trying to get a count of rows that have the column Canceled with value 1. In the past I used the solution I found on Stackoverflow to use the Sum function with IIF, i.e.
=Sum(iif(Fields!Canceled.Value="True", 1, 0))
But now my source data has multiple rows for one booking_id so I need to add a distinct on that column. In SQL I could easily do
SELECT COUNT(DISTINCT(booking_id)) FROM Booking WHERE Canceled=1
But I can't figure out how to get the same behaviour in Report Builder 3.0. Any ideas?
Doing this in T-SQL, if possible, as suggested in the comments is not a bad idea, but you can do this in the report with an expression like:
=CountDistinct(IIf(Fields!Canceled.Value = 1, Fields!booking_id.Value, Nothing))
CountDistinct will ignore Nothing (i.e. Null) records, so you can apply a CountDistinct to an IIf expression that returns booking_id or Nothing based on Canceled.
I am trying to use parameters within my expression because I won't be able to use the parameters in the dataset, I am trying to do a simple expression but I am struggling to figure out what I am doing wrong, here is what I want to achieve:
I want to count the rows when the Month(Date) = #Month.
What I have so far:
=IIf(Month(Fields!Date_Logged_SQL.Value) = Parameters!rpMonth.Value,CountRows(),Nothing)
My results return no values which I am assuming must be something to do with my false return.
You need to use the IIf expression as part of a larger aggregation expression, something like:
=Sum(IIf(Month(Fields!Date_Logged_SQL.Value) = Parameters!rpMonth.Value,1,0))
For each row in Scope, this will either add 1 or 0 to the running total of rows that fulfill your check, the end result being the total of rows that match the month.
Depending on where you're adding the expression, you may need to add a Scope parameter to get the correct result, e.g. something like:
=Sum(IIf(Month(Fields!Date_Logged_SQL.Value) = Parameters!rpMonth.Value,1,0), "DataSet1")
Currently I am trying to average a set of numbers, but with certain conditions.
Is it possible to use an iif() within an avg() and return the correct result?
Furthermore, as of now my computations return a decimal returned to a power (8.9267....E -05).
I tried circumventing the AVG function by conditionally summing and then dividing by a conditional count but it gives me the same results.
Can someone explain why this is returned and offer help?
Currently I have:
=avg(iif((This_case) AND (That_case) AND (This_conditional)
, Fields!ResponseRate.Value
, 0))
Essentially I want the average ResponseRate if certain conditions are met.
The sum function works fine for the conditions but the average doesn't.
You can definitely use IIf within Avg and get the correct results.
Do you want to exclude the False values from the calculation entirely?
In your example you're still including them, just setting them to 0 and hence still including them in the calculation. This might explain your unexpected results.
If you want to exclude them entirely use Nothing instead of 0.
Edit after comment
You can nest an expression in another IIf statement and check for NULL values using IsNothing.
Say your condition average expression is:
=Avg(IIf(Fields!ID.Value > 5, Fields!value.Value, Nothing))
You can return 0 for NULL values with something like:
=IIf(IsNothing(Avg(IIf(Fields!ID.Value > 5, Fields!value.Value, Nothing)))
, 0.0
, Avg(IIf(Fields!ID.Value > 5, Fields!value.Value, Nothing)))
I'd like to add my two cents to this one, a little late, but also valuable. I was able to use the above code to Average out a data set if another record appears X number of times.
=AVG(IIF(Count(Fields!AcctNo.Value, "AcctNo1") = 2, Fields!Limit.Value, Nothing))
So, if the acctno field appears 1 time, avg the limit field for that row group. Ian's example was very helpful