I have two datasets - In dataset 1 MedAdministration I have Medical_Condition. In dataset 2 ProblemList I have Medical_Condition. I want to combine both datasets and count.
For instance Heart attack may be in dataset 1 and in dataset 2. I just want the report to show Heart Attack 20 which would be a combination of both datasets and the total from both into one total on the report.
I have tried the lookup function and the join, but I keep getting errors.
=Lookup(Fields!Medical_Condition.Value,Fields!Medical_Condition.Value, "ProblemList")
"System.Web.Services.Protocols.SoapException: The Value expression for
the textrun ‘Medical_Condition.Paragraphs[0].TextRuns[0]’ has an
incorrect number of parameters for the function ‘Lookup’. at
Microsoft.ReportingServices.Library.ReportingService2005Impl.SetReportDefinition(String
Report, Byte[] Definition, Guid batchId, Warning[]& Warnings) at
Microsoft.ReportingServices.Library.ReportingService2005Impl.SetReportDefinition(String
Report, Byte[] Definition, Warning[]& Warnings) at
Microsoft.ReportingServices.Library.ReportingService2010Impl.SetItemDefinition(String
ItemPath, Byte[] Definition, String expectedItemTypeName, Property[]
Properties, Warning[]& Warnings) at
Microsoft.ReportingServices.WebServer.ReportingService2010.SetItemDefinition(String
ItemPath, Byte[] Definition, Property[] Properties, Warning[]&
Warnings)
I can't even get it to combine the data, let alone count it. What am I doing wrong?
Thanks in advance!
Tara
Lookup function takes 4 parameters:
Lookup(source_expression, destination_expression, result_expression, dataset)
To expand on SuperSimmer's answer, you'll need to use the correct lookup parameters within your expression to add the two. I don't know for sure how the report is laid out, but for example, if you need values summed for Heart Attack, you'll need a count of that field from each dataset and add those together.
=Count(IIF(Lookup(Fields!Medical_Condition.Value,Fields!Medical_Condition.Value, Fields!Medical_Condition.Value, "ProblemList") = "Heart Attack", 1, Nothing))
+ Count(IIF(Lookup(Fields!Medical_Condition.Value,Fields!Medical_Condition.Value, Fields!Medical_Condition.Value, "MedAdministration") = "Heart Attack", 1, Nothing))
If you'd prefer a dynamic result or if the 'Condition' is provided from a parameter, you'd replace the "Heart Attack" with Parameters!Condition.Value to check each dataset for the value provided.
Related
I have this error message that pops up when trying to run a report. It is a SSRS Report for Dynamics AX 2012.
System.Web.Services.Protocols.SoapException: The Visibility.Hidden expression for the text box ‘Textbox183’ has a scope parameter that is not valid for an aggregate function. The scope parameter must be set to a string constant that is equal to either the name of a containing group, the name of a containing data region, or the name of a dataset.
at Microsoft.ReportingServices.Library.ReportingService2005Impl.CreateReport(String Report, String Parent, Boolean Overwrite, Byte[] Definition, Property[] Properties, Guid batchId, Warning[]& Warnings)
at Microsoft.ReportingServices.WebServer.ReportingService2005.CreateReport(String Report, String Parent, Boolean Overwrite, Byte[] Definition, Property[] Properties, Warning[]& Warnings)*
This expression below is set on a textbox's visibility.
Format(sum(IIF(Fields!InventOnHand.Value <= Parameters!CutOff.Value, Sum(Fields!InventOnHand.Vallue), 0 )), "#, ##0.00")
Please help me understand why that error above shows and how to fix this expression.
When do you want to see your text box? Your expression is calculating a dollar amount and not resulting in a True/False condition need for Visibility.
Since the error is asking about your dataset, I assume it's not in a table - a text box in a table wouldn't need a dataset sine the table is associated with a dataset.
Assuming that you only want to see the text box when the SUM of Inventory is greater than the CutOff parameter, you'd want:
=IIF(SUM(Fields!InventOnHand.Value, "Dataset1") <= Parameters!CutOff.Value, True, False)
I have a varchar field (i am grouping on) in a dataset that returns a list of values : 20, 25, 40, 100, 110, 'N/A'..
I want the "numeric" values sorted from low to high : i.e : 20, 25...110, 'N/A'
the problem is that the A>Z sorting in the grouping gives out the following output :
100, 110, 25, ..., N/A
I cannot convert to numeric datatype since there are string values..
Does anyone have a solution please ?
Thank you in advance
Jam
There are several solutions you can implement here. I'll discuss the two I consider to be the easiest. If these don't work for you, let me know because there are a multitude of options. To make it easy, I've named the field you're referring to in your question as *num_text*.
Fix in SSRS:
Go to the Tablix Properties for the tablix displaying the data in question. Go to Sorting tab. Click Add. In the "Sort by" field, click the expression button and type the following:
=CInt(IIF(Fields!num_text.value = "N/A",9999999,Fields!num_text.value))
Note, you need to convert any possible text values to a number greater than any possible integer/decimal. In this case I chose 9999999 based on the examples in your question. If you have multiple text values that are not converted to number, Report Builder/BIDS will allow you to save the report, but when you render it, it will show #Error, signifying that the CInt (or any other conversion formula you choose) failed on a non-numeric value.
Fix in SQL:
Add a new field (like field_sort) with datatype numeric and use your case statement generating the current field in question saying:
, Case
When --Criteria leading to "N/A"
Then 9999999
Else num_text
End as field_sort
--Rest of SQL Script here
Order by field_sort
Then just display your num_text field in SSRS, and the values will be sorted properly. If you have many possible string values, then you might find it easier to fix in SQL (rather than specifying numerous IIF statements in SSRS.
The matrix's odd rows contain strings, representing integer numbers. The even rows contain strings, representing dates in mm/dd/yyyy format. The order is not guaranteed, it could be the other way around if someone changed the category names.
The grand total row has to be added to this matrix, but the following expressions throw an #Error:
=Sum(Iif(IsDate(Fields!Data.Value), 0, CInt(Fields!Data.Value)))
=Sum(Iif(InStr(Fields!Data.Value, "/"), 0, CInt(Fields!Data.Value)))
Converting 0 and field value to some other numeric data types did not work too.
Interesting enough, the expressions partially work for the grand total column, i.e. they calculate the numbers' row total, but #Error on the dates rows.
Protecting the row grand total as follows did not help either:
=Iif(Fields!Results.Value = "# of items", CStr(Sum(CInt(Fields!Data.Value))), "")
What is the correct way to implement data driven conditional totals?
I could do this in plain SQL and dump into a tablix in a heartbeat but this has to be wrapped in SSRS and used with an existing matrix which must not be changed otherwise.
The #ERROR you get on the date rows is due to the CInt conversion failing.
This is because IIF is a function, not a language construct so both the true and false parameters get evaluated before being passed to the function regardless of the value of the boolean condition parameter. This means that:
=Sum(Iif(IsDate(Fields!Data.Value), 0, CInt(Fields!Data.Value)))
will always attempt the conversion to integer regardless of the result of the IsDate function.
Try using Val instead of CInt. The problem with CInt is it errors when the string to be converted is an inappropriate form; Val doesn't have that problem - it simply grabs whatever numbers it can. So you can use the expression:
=Sum(Iif(IsDate(Fields!Data.Value), 0, Val(Fields!Data.Value)))
and then simply format it like an integer.
Note that the Val function is still being run even when the field is not numeric but this expression succeeds because the Val function doesn't raise errors like Cint. We simply make the calculation and discard the result when the field is a date.
This expression, combining the tips from both answers with additional protection, works:
=Iif(
IsNumeric(Fields!Data.Value),
Sum(Val(Iif(InStr(Fields!Data.Value, "/"), "", Fields!Data.Value))),
0
)
i have a report that i have been sending a parameter to which worked just fine.
the report parameter was declared:
string[] pclist = new string(){ "A", "B", "C" };
ReportParameter pcode = new ReportParameter( "pcode", pclist, false );
which gives me a new report parameter that is initialized with a string array of 3 values. so far so good.
inside the report, the 'pcode' parameter is defined as a 'String', and is used like:
...
and PCode in ( #pcode )
...
recently, because the values for the parameter needed to change depending on who is logged in, we changed this such that the parameter gets it's string array from the return value of a method call. (the method gets the values from the database):
ReportParameter pcode = new ReportParameter( "pcode", FetchParams("X"), false );
FetchParams("X") performs a select on the database and returns a string[] of values. most of the time it works fine. however, sometimes the report does not run and only returns the error message:
The 'pcode' parameter is missing a value
what we determined is that sometimes there are dozens of values be returned by FetchParams("X"). when the number of values in the string[] gets too big, the report fails with that error message. apparently, there is some kind of upper limit to the number of values that can be used to instantiate a ReportParameter object.
initially we thought that the limitation might be in sql server itself as a limit to the number of values that can be handled by an in clause. however, the error message does not seem to support this conclusion.
edit: trial and error has shown for this particular case, 33 is the upper limit for the number of values in the string array.
does anyone have any experience with this problem?
is there an upper limit to the number of values in the array passed to the ReportParameter ctor?
is there a way to configure the upper limit to be a larger number?
any and all help will be appreciated.
thanks!
hokay, folks, here is the real answer to this bit of mystery.
the report has a parameter called 'pcode'.
the 'pcode' parameter has a data source that creates a list of drop down values.
now the code that runs the report is generating a list of values for the pcode parameter.
when the list of values is passed to the report, if there is a value that doesn't match the report's list generated from it's data source, you get the mind-numbing ssrs error message:
The 'pcode' parameter is missing a value
ug-ly. but that's m$ for ya.
for the record, there does not seem to be a limit to the number of values in the string array being passed to the ReportParameter ctor... that and the error message is coming from ssrs, not the code generating the ReportParameter object.
hope this might help someone else that has this problem.
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.