I'm trying to add multiple iif statements to one field in a query. It is not working if I try to put it all together. I don't know how to do this and make it work. I've tried several different ways.
This is what I have:
IIf(([M1]='A') OR ([M1]='J') OR ([M1]='S'), 1,0)
IIf(([M1]='B') OR ([M1]='K') OR ([M1]='T'), 2,0)
IIf(([M1]='C') OR ([M1]='L') OR ([M1]='U'), 3,0)
You're looking for the Switch function. That takes an unlimited amount of parameters, and for the first odd-numbered parameter that's true, the even-numbered parameter after it gets returned.
Switch(([M1]='A') OR ([M1]='J') OR ([M1]='S'), 1,
([M1]='B') OR ([M1]='K') OR ([M1]='T'), 2
([M1]='C') OR ([M1]='L') OR ([M1]='U'), 3
True, 0)
Related
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)
This should be easy, but I am stuck.
I have a table listing some figures about Qualifications - to achieve which a dataset that is essentially a row per Student is being grouped on Qualification with a Parent Grouping on "Measure" (which is just a bucket of qualifications).
One of the columns is trying to work out the number of students (well, more properly the number of students with a value in a particular field, weighted by another field) in each Measure/Qualification. In the screenshot below, it's the "Pred. Avg" column on the right hand side.
So for the Qualification Row Grouping, that column is calculated by:
=CountDistinct(Iif(IsNothing(Fields!AVG_PTS.Value) = False, Fields!Learner_ID.Value, Nothing), "Qual") * Lookup(Fields!Qual_Code.Value, Fields!Qual_Code.Value, Fields!size.Value, "DS_KS5Nationals_LKP")
This works fine - the values of 35 and 11.5 in that rightmost column are correct for those rows. What the top row should be doing is simply adding up the values in the other rows to give me the number of students in this Measure, in this case to give 46.5. To do that the expression I am using is:
=Sum(CountDistinct(Iif(IsNothing(Fields!AVG_PTS.Value) = False, Fields!Learner_ID.Value, Nothing), "Qual") * Lookup(Fields!Qual_Code.Value, Fields!Qual_Code.Value, Fields!size.Value, "DS_KS5Nationals_LKP"), "Measure")
However as you can see in the screenshot, this returns 2917 instead.
So my question is; Why doesn't that work, and given that it doesn't work how can I, within a parent group, aggregate the results of aggregates inside a child group?
EDIT:
OK so, I have determined that the following works correctly:
=Sum(CountDistinct(Iif(IsNothing(Fields!AVG_PTS.Value) = False, Fields!Learner_ID.Value, Nothing), "Qual"), "Measure")
The problem there is that the Qual row that returns 11.5 is weighted to 0.5. I.E. it actually returns 23, and the Lookup(Fields!Qual_Code.Value, Fields!Qual_Code.Value, Fields!size.Value, "DS_KS5Nationals_LKP") is for that row returning 0.5 and altering it to 11.5...so the question becomes; "how do I force that ...*Lookup(Fields!Qual_Code.Value, Fields!Qual_Code.Value, Fields!size.Value, "DS_KS5Nationals_LKP") into the "Qual" scope, like the CountDistinct() is already in?
The issue here is that you're trying to aggregate values using that Lookup function which only returns one value. There are a couple ways you could go about doing this. One option would be to use the LookupSet function to get the applicable weightings. An even better option is to combine the data in your dataset so that the weighting is available without using a lookup. That way the function can recalculate an any grouping level without you having to force a scope on it. Also, CountDistinct ignores "Nothing" so you can do without the extra IIf statement. Hope that helps.
I have been working on ssrs and tried to do the following statement. I am using data from 2 datasets and there is no way I can merge them into one (I tried that when I first had this error). Code:
=Sum(iif(Fields!Year.Value = Max(Fields!Year.Value) - 1 , Sum(Fields!PersonCount.Value, "RetCust"), 0))
This code gives the error: The Value expression for the text box has a nested aggregate that specifies a dataset scope. Inner aggregates cannot specify a dataset scope.
I have also tried a different variation of this code which is as follows:
=(iif(Fields!Year.Value = Max(Fields!Year.Value) - 1 , Sum(Fields!PersonCount.Value, "RetCust"), 0))
I just got rid of the sum at the beginning. But this time I had a different error: Report item expressions can only refer to fields within the current dataset scope or, if inside an aggregate, the specified dataset scope. Letters in the names of fields must use the correct case
Hope someone can help :)
Cheers
Your expression is a bit wrong.
=Sum(iif(Fields!Year.Value = Max(Fields!Year.Value) - 1 , Sum(Fields!PersonCount.Value, "RetCust"), 0))
Your Sum is outside and is covering the two fields which is not on the same dataset. You should assign Sum for each of them since they are from different dataset.
Try this:
=iif(Sum(Fields!Year.Value) = Max(Sum(Fields!Year.Value)) - 1 , Sum(Fields!PersonCount.Value, "RetCust"), 0)
Note: I haven't tested the Max(Sum(.... if that's correct.
I'm currently trying to have multiple if statements in my expression builder for multiple check boxes that I am ticking to alter the primary row data.
If I check block, the primary row of data changes to 0, from, say, 100.
If I also check prefer, it doubles the data, from 100 to 200.
Here's what I have so far:
IIf([block],0,[baseWeight]/329*100) +
IIf([prefer],[weightAfterPrefer]/329*100,[baseWeight]/329*100)
Currently, the '+'operator adds them both together and it's not working properly. It's doubling the data with this expression. I don't want the data to change unless I have a Yes/No box checked.
You can put a second IIf into the True or False clause of the first IIf.
You didn't tell exactly how it should behave, but my guess would be this (formatted for readability):
IIf([block],
0,
IIf([prefer], [weightAfterPrefer]/329*100, [baseWeight]/329*100)
)
In SSRS 2005, I'm trying to set up an expression to return true or false, according to whether the value of one of the ReportItems is in a list of (possibly multiple) values selected by the user from a list when the report is run.
Here's the expression so far:
=iif(Trim(ReportItems!Category_2.Value) = Trim(Parameters!Category.Value(0)), False, True)
You can see that True and False in the expression are reversed - this is because it's to control the 'Hidden' property of the row, and I want to NOT hide rows where the value is in the list.
The expression works fine when choosing single values for the parameter, but for multiple values, it only displays the results for the very first.
Hope you can help.
Try using
=iif(Trim(ReportItems!Category_2.Value) = Trim(Parameters!Category.Value), False, True)
Many thanks for your help. These multiple values were really bugging me, and I never managed to get Trim to work properly, so I ended up using the following two-stage solution, instead:
(1) In the SQL 'SELECT' statement, I defined a new value called 'InCategory', assigning it a value of 1 or 0 according to whether the Category was one of the inputted Categories or not:
CASE WHEN Category IN (#Category) THEN 1 ELSE 0 END AS 'InCategory',
(2) Then in SSRS, my expression for the 'Hidden' in the report became simple, hiding the row if the sum of 'InCategory' for that row was 0:
=iif((Sum(Fields!InCategory.Value) = 0), True, False)
Thank you again for your help - I much appreciate it, and will use this site again.