SSRS IIF Expression across Multiple DataSets - reporting-services

I'm trying to do an IIF expression on a 2nd dataset to sum the 'BookingsComfirmed2016LASTWEEK' column and then divide it by the sum of the 'Stock2016Week' column in the dataset I'm in and where the PropertyTypeCategory = Cottage, but with no joy. I'm sure it's something to do with the placement of the 2nd dataset name, but would appreciate any help. Regards Claire
Dataset1 = TradingLastWeekandYTD
Dataset2 = TradinglastWeekandYTDSTOCK
=(IIF(Fields!PropertyTypeCategory.Value, "TradingLastWeekandYTD" = "Cottage",Sum(Fields!BookingsConfirmed2016LASTWEEK.Value, "TradingLastWeekandYTD")) /(IIF(Fields!PropertyTypeCategory.Value = "Cottage", Sum(Fields!Stock2016Week.Value)),0)

Your iif() won't work like this.
You can't check row by row in a dataset you're not currently working in, which is what you are trying to do with the first part of the iif().
You can use custom code to do an aggregated lookupset() to get the values of the first part.
This link https://itsalocke.com/aggregate-on-a-lookup-in-ssrs/ will help you do the custom code.
For the lookupset(), you would have to do something like..
=Code.SumLookup(lookupset(Fields!PropertyTypeCategory.Value, "Cottage", Fields!BookingsConfirmed2016LASTWEEK.Value))
This assumes that your custom code function is called "SumLookup". It will sum all the values that the lookupset() returns.

Related

SSRS Dataset get a row based on specific criteria

I have a dataset called Box as below:
Dataset Called Box
I am trying to rewrite this Crystal Reports command If {Name} like "Train*" Then
{volume} in SSRS as =IIf(Fields!NAME.Value="Train", Fields!VOLUME.Value, Nothing) or =IIf(Left(Fields!NAME.Value,3)="Tra", Fields!VOLUME.Value, Nothing) I need to get the last value 9977, but I cannot use Last function in SSRS, as the order might change.
Please suggest.
Thanks.

ssrs Summing two fields same dataset, different tablix

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)

Multiple datasets Count with IIF in SSRS

I am trying to write an expression in SSRS which counts only specific data using IIF. I found the following solution:
=Sum(IIF(Fields!Program.Value = "FC", Fields!QuantityToShip.Value, 0))
The code above works but only when there is ONE dataset, while I have several.
Here is the code I wrote:
=Count(IIF(Fields!Mgroup.Value,"DataSet1"=303,1,0))
I get the aggregation error:
Textbox refers directly to the field ‘Mgroup’ without specifying a dataset aggregate
I added a sum:
=Count(IIF(Sum(Fields!Mgroup.Value,"DataSet1")=303,1,0))
Still getting the same error.
Why is that?
What can I put instead of Sum? All I need is to count how many groups named 303 I have.
The expression you used has some sintax errors. The Count function only aggregate from the scoped Dataset.
Try this:
=LookupSet(303,Fields!Mgroup.Value,Fields!Mgroup.Value,"DataSet1").Length
Let me know if this helps you.

SSRS Filter with a different column from a different dataset

I want to filter my column, let's call it AllStudentID from dataset1 with another column from a different datset.
Dataset1 had many column such as AllStudentID, Class, Time, Location.
Dataset2 has other columns but i'm focused on a similar column called OnCampusID.
I've tried looking into using a filter but since the report itself has the columns from Dataset1, i run into an issue where if I select the column in dataset2, it always gives a First(OnCampusID). And I don't want that.
I looked into IIF() but again, i'm using a column from a different datset plus if let's say that they are NOT equal, I don't want to display anything, instead of putting something there. I know that you have to put a result if true and a result if false.
If I"m thinking of it in terms of SQL statements, it's like having a WHERE clause WHERE AllStudentID=OnCampusID.
I tried running a Parameter but I don't want the select part on the top but rather have the report filtered already.
Am I missing something? I know it has to be simple.
Mind you, the following example above is just an example i made up, not the real thing.
Assuming that each OnCampusID only appears once in Dataset2 then you can do a Lookup expression to filter it:
=IIF(IsNothing(Lookup(Fields!AllStudentID.Value, Fields!OnCampusID.Value, Fields!OnCampusID.Value, "Dataset2")), False, True)
If OnCampusID appears more than once in Dataset2 then do the same thing using LookupSet.
To get the graduate field from Dataset2 just to a Lookup in the Value of the cell, like so:
=Lookup(Fields!AllStudentID.Value, Fields!OnCampusID.Value, Fields!Graduate.Value, "Dataset2")

SSRS: Get values from a particular row of DataSet?

My dataset currently has 12 rows of data. Each representing data for a month. I would like to have variance of a column between to rows, the rows being last & last but one i.e., latest month and previous month's data.
It could have been simple if I were to work on tablix but thats not the case. I want those values for a textbox.
Any ideas on it anyone?
I hope you are using SSRS 2008R2:
R2 introduced the Lookup function that is perfect for this scenario.
=Lookup( Fields!ProductUID.Value ,Fields!ProductID.Value,Fields!Price.Value,"PriceDataSet")
The Lookup function above will evaluate the first parameter ("Fields!ProductUID.Value") in the current dataset, then look for a matching value in the field specified in the second parameter ("Fields!ProductID.Value") in the dataset specified in the fourth parameter. The value of the third parameter is then evaluated in that row of the dataset and returned.
A little convoluted, but very helpful.
In your case, you can use this in a textbox with a calculated a static number:
=Lookup(
Month(DateAdd(DateInterval.Month, -1, GetDate())),
Fields!MonthID.Value,
Fields!Name.Value,
"DataSet1")
This should calculate a number for last month, then look for a match in DataSet1.
In this example I have a tablix with Statecode and name as below
enter image description here
Suppose you want to display the name of state of CA, write an expression as -
=Lookup(
"CA" ,
Fields!StateCode.Value,
Fields!StateName.Value,
"ReportData"
)
This will return 'California' in the text box
I ran across this post while trying to solve a similar problem but with columns of double data type. Not sure why but SSRS did not want to return my first row using LOOKUP in combination with ROW_NUMBER in SQL(If someone can solve that all the better). I ended up using a SUM(IIF) instead. Hopefully, this is useful for someone else.
=Sum(IIF(Fields!RowNum.Value=1,CDBL(Fields!MyNumericColumn.Value),CDBL(0)))
Note: If SSRS complains about data types, just cast both parts of the IIF to the desired data type.