Multiple datasets Count with IIF in SSRS - reporting-services

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.

Related

what countrows().equals() means in SSRS

I can't understand the structure of the written code
(CountRows("client_code").Equals(Parameters!client_code.Count)
can anyone explain this please?
And where can I find a reference for all the functions that I can use to write Expression in SSRS??
In SSRS we use "=" operator for comparison rather than equals.
Expression mentioned by you below
(CountRows("client_code").Equals(Parameters!client_code.Count)
Rather it should be like
=IIF(CountRows("client_code")=Parameters!client_code.Count,true,false)
What your mentioned code does: It Returns a count of rows within the specified scope, Scope can be Group as well. and it compared with your Report Parameter count.
Here you will find complete list of functions and expression for SSRS.

Conditional Aggregate Lookup - SSRS

I have a report with two datasets to summarise the number and value of incomplete orders by status. I have a "Back Order" column, which is using the 'Lookup' function to refer to a second database, based on a whether the Fields!IsBackorder.Value returns true. This works at line level, but I've run into issues at the aggregate level.
For the total count of orders, this forumula works:
=SUM(IIF(LOOKUP(Fields!SalesOrderID.Value, Fields!SalesOrderID.Value, Fields!IsBackorder.Value, "DstBackorders") = "TRUE",1,0))
However, for the total value of orders ("Fields!NetValue.Value"), this returns '#Error'
=SUM(IIF(LOOKUP(Fields!SalesOrderID.Value, Fields!SalesOrderID.Value, Fields!IsBackorder.Value, "DstBackorders") = "TRUE",Fields!NetValue.Value,0))
I've tried custom aggregate functions but I haven't found any that work. I'm not sure how I'm getting this error.
Any suggestions would be really helpful.
Thanks,
Report Screenshot
The syntax looks perfectly fine , also the lookup looks good , can you please check on the below things in your DataSet:
Is Fields!NetValue.Value in scope of the current DataSet.
Are we using the correct data type for Fields!NetValue.Value(Something which is aggregatable , like int , decimal etc.)

SSRS standalone formulas

I have been working on this for days without being able to solve yet. It's probably simple if you know what you're doing. I'm simply trying to make a standalone formula that is not in a tablix or anything, it's just in a textbox.
Here is an example of my Dataset called Dataset1:
What I am trying to get is a sum of the Actual Cost when the Category is Labor from Dataset1. My current expression is:
=Sum(iif(Fields!Category.Value="Labor", Fields!ActualCost.Value, 0), "Dataset1")
I refer to Dataset1 as my scope because otherwise, I get an error about using an aggregate expression without a scope.
The report runs but shows #Error in the textbox that has my expression in it. When I replace Fields!ActualCost.Value with a 1, I get the answer, 5, which is the correct number of rows with Labor as the Category. But it won't let me sum the numbers in the ActualCost column where Category is Labor.
Any ideas as to what I'm doing wrong? I feel like it's something to do with aggregating, but I'm not sure. Thanks!
It may have to do with the datatype of fields!ActualCost.Value. If that field is a decimal (regardless of how you have it formatted), try using cdec(0) instead of just 0 in your expression.

SSRS IIF Expression across Multiple DataSets

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.

SSRS Displaying Comma Delimited or Distinct Values in Single Column

I have a relationship like this:
I'd like to display the Acctnbr field in SSRS like this as a single field:
I have tried expressions like this
=Join(LookUpSet(Fields!Baseacctnbr.Value,
Fields!Baseacctnbr.Value,
Fields!Acctnbr.Value,
"DataSet1"), ",")
and I get an error message that reads:
Aggregate, Rownumber, runningvalue, previous and lookup functions cannot be used in calculated field expressions.
I can get the comma delimited field from SQL using the STUFF function, but my SSRS report is grouping and when I group I loose the SQL code.
How can I get this to work?
Much appreciated!
Using this dataset to test I recreated your scenario.
Try using your expression in a column of your tablix:
I've added the expression you posted in the cell is highlighted.
It will preview the following table.
Let me know if this can help you.