SSRS function needs to read field from additional dataset - function

So in the custom code in SSRS this function is reading a field from a different data set. To be specific the field is "TOTAL_WORK_HOURS".
Public Function CRFtotalhourswobreak(Fields As Microsoft.ReportingServices.ReportProcessing.ReportObjectModel.Fields) As Double
Return Fields!TOTAL_WORK_HOURS.Value - CRFbreakhours(Fields)
End Function
Because that field is in a dataset not being used by the Tablix, the field simply isn't being read. I know this to be true because whenever I replace the field with random number, I do get results.
Is there proper syntax to implement a field that isn't in the main dataset?

you can use
=First(Fields!TOTAL_WORK_HOURS.Value, "DataSet1")

Related

Passing parameters to a Dataset from an expression in SSRS

In a report I would like to have the individual static text fields internationalised.
The idea is to have a default word or phrase like "Date and Time" and pass this string to a dataset with static parameters such as Culture_Code.
My question is how do I set the value of the parameter to pass to the dataset BEFORE calling the dataset within each individual expression of each text box?
Example expression;
Parameter!Text_To_Translate.Value = "Date and Time"
=First(Fields!Translated_Text.Value, "Language_Text")
I am using SSRS 2008R2.
if you want to pass the parameter before calling the dataset then you have to pass the parameter in the url of reportserver
http://localhost/reportserver
url format:
http://<localhost/servername>/reportserver/Pages/ReportViewer.aspx?<report_name>&rs:Command=Render&parameter_name=value
here the way you have to pass the value.
If your report layout is such that all of the text fields to be internationalized are in one or two regions, it may be better to set those regions up as data regions and use a separate query (or queries) to populate them, based on your Culture_Code parameter value.
This assumes you are pulling the localized values out of a data source you can connect to - which may be updated or extended over time.

Match field value of parameter from the same dataset using ssrs

I have a dataset FiscalYearMonth which contains
Fiscalmonthyear
Fiscalmonthkey
I have also Parameters!FiscalYearMonth.Value
How can I get Fiscalmonthkey for FiscalYearMonth parameter ? I tried the following expression but didn't work
=lookup(Fields!FiscalMonthYear.Value,Parameters!FiscalYearMonth.Value, Fields!FiscalMonthKey.Value, "FiscalYearMonth")
I think you have your function parameters in the wrong order, try this:
=lookup(Parameters!FiscalYearMonth.Value, Fields!FiscalMonthYear.Value, Fields!FiscalMonthKey.Value, "FiscalYearMonth")
This bascially says "in the dataset 'FiscalYearMonth', compare the value of Parameters!FiscalYearMonth.Value to the field Fields!FiscalMonthYear.Value for each row in the dataset and return the value of Fields!FiscalMonthKey.Value where there is a match".
Note that the Lookup() function only returns a single value and will stop at the first match found.

SSRS expression replace NULL with another field value

I need to write an SSRS expression to check and replace NULL field value with another field value. Can this be done?
=iif(isNothing(Fields!FV1.Value), Fields!FV2.Value, Fields!FV1.Value)
If you have to do it a bunch of times, you can also make a reusable function to avoid a lot of typing. Here's a solution modeled off of SQL's ISNULL function:
Right click on the Report Document and go to Report Properties.
Navigate to the Code tab and add the following function:
Public Function IsNull(input As Object, defaultValue As Object) As Object
Return IIf(input Is Nothing, defaultValue, input)
End Function
Note - Even though the custom code is expecting valid VB.NET code, you have to use the IIF Ternary operator.
Then you can use it in an expression like this:
=Code.IsNull(Fields!MyField.Value,0)

SSRS error: Conversion from string "string;#NA" to type 'Date' is not valid

My datasource is XML (sharepoint list). I basically want to show the date formatted if the value in the field is a date and if not then show "NA". For some reason, even when the data is a a string it is still trying to convert it to a date somewhere. Here is my code..
=IIF
(
ISDATE(replace(First(Fields!ows_Manufacturing_Date.Value, "DataSet1"),"datetime;#","")),
formatdatetime(replace(First(Fields!ows_Manufacturing_Date.Value, "DataSet1"),"datetime;#",""),2),
replace(First(Fields!ows_Manufacturing_Date.Value, "DataSet1"),"string;#","")
)
The problem is that the IIF statement in SSRS doesn't short circuit, it always evaluates both conditions, so even if the field is not a date, it still tries to do the formatdatetime function.
(See this: SSRS iif function question)
Instead of the IIF function, try using the SWITCH function instead:
=SWITCH(First(Fields!ows_Manufacturing_Date.Value, "DataSet1")="string;#NA",
"NA",
First(Fields!ows_Manufacturing_Date.Value, "DataSet1")<>"string;#NA",
formatdatetime(replace(First(Fields!ows_Manufacturing_Date.Value, "DataSet1"),"datetime;#",""),2))

How to loop rows of dataset in Reporting services rdl custom code

How can I loop through the rows of a dataset in the custom code?
I have a report containing a dataset. I pass the dataset as a parameter to the custom code function. But what then? Where is a reference about the available members etc.?
Here is my dummy sample code so far:
Public Function ShowParameterValues(ByVal ds as DataSet) as object()
Dim codes() As Object
Array.Resize(codes,dc.???.Count)
codes(0)=ds??(field???)(row??)
return codes
End Function
Please note: this will be a very simple script (if it'll work), so I don't want to go into custom assemblies etc.
I think you got your answer at:
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/a7d59224-0ee5-491e-883b-2e5fcb3edeab/iterate-through-rows-of-dataset-in-reports-custom-code?forum=sqlreportingservices
There were two important pieces of information I was able to grasp from the above link:
First, A dataset in Reporting Services is not the same type of object as an ADO.Net dataset. A report dataset is an internal object managed by the SSRS runtime (it's actually derived from a DataReader object) and not an XML structure containing datatables, etc. and cannot be passed into the report's custom code.
Second, There was a solution posted as to how one can Iterate through rows of dataset in report's custom code by "transforming" the data set into a multivalued parameter (or if several fields are needed, transforming it in multiple multivalued parameters):
The multivalued Report Parameter must have the following characteristics:
Hidden = True, Allow Multiple Values = True
Available Values tab: Choose the desired dataset. Select the searchable id as Value id, and the field you want to expose as Label Field.
Default Values Tab: Get Values from a Query.
Choose the same Dataset as choosen in the available Values Tab.
Value Field the same you choose for value id.
Set the parameter to never refresh (or it will be loading the data from each iteraction of another parameter).
Now, the idea is make this Parameter "searchable". From this point you exposed the Dataset as an array in the Multi valued Parameter.
Now in a custom code insert the following code:
function GetDataSetLabelFromValue( id as integer) as String
dim i as integer
i = 0
for i = 1 to Report.Parameters!YourParameter.Count()
if Report.Parameters!YourParameter.Value(i) = id then
GetDataSetLabelFromValue = Report.YourParameter!ReportParameter1.Label(i)
Exit For
End if
next i
End Function
Were you able to do what you wanted?