While there are many code samples for the individual pieces of this question, as a neophyte with Report Designer, I cannot get the syntax for this correct.
I have a textfield that I want to display a SUM of "Held Hours" from one of three DataSets, and this is determined by another field in that same DataSet having a value of "H."
So taking it in pieces, this works to sum ALL hours in ReportDataset.
=Sum((Fields!RegHrs.Value + Fields!OvtHrs.Value),"ReportDataset")
Now, somehow i need to nest that in an IIF. I need that SUM expression to be the "True" return from the IIF when the BillStatus = "H."
IIF(Fields!BillStatus.Value = "H",true,false)
I cannot seem to figure out how to combine the IIF and the SUM so that they pull from "ReportDataset" and are syntactically correct.
I've been trying various permutations of this:
=Sum(IIF(Fields!BillStatus.Value = "H",((Fields!RegHrs.Value + Fields!OvtHrs.Value),"ReportDataset"),0))
Any pointers?
New Info:
The following reports as syntactically correct, but gives me 0 for a return value.
=Sum(IIF(Fields!BillStatus.Value = "H", (Fields!RegHrs.Value + Fields!OvtHrs.Value),0),"ReportDataset")
There should be hundreds of hours returned.
Try a nested sum:
=Sum(IIF(Fields!BillStatus.Value = "H", Sum(Fields!RegHrs.Value + Fields!OvtHrs.Value,"ReportDataset"),0),"ReportDataset")
Or:
=IIF(Fields!BillStatus.Value = "H", Sum(Fields!RegHrs.Value + Fields!OvtHrs.Value,"ReportDataset"),0)
Can you do it in your dataset using SQL? If so, just use the following:
SELECT CASE WHEN BillStatus = 'H' THEN RegHrs + OvtHrs END AS HeldHours
FROM MyTable
Then all you need to do is sum this field:
=Sum(Fields!HeldHours.Value, "ReportDataSet")
Related
I got a little problem with Lookupset on a SSRS Report.
The report has a father-child structure in the group section and the datasets come from different tabular.
The problem occurs when one of the Product from Dataset1 is missing on Dataset2, the entire sum returns 0.
I tried this VB code in order to sum up all the values the Lookupset is able to return.
Function SumLookup(ByVal items As Object()) As Decimal
If items Is Nothing Then
Return Nothing
End If
Dim suma As Decimal = New Decimal()
suma = 0
For Each item As Object In items
suma += Convert.ToDecimal(item)
Next
Return suma
End Function
I expected the sum of every Product Lookupset is able to retrurn me but it is just returning 0 if one of the Products is missing in Dataset2.
Is there a way to manage the Nothing returned by Lookupset?
Sorry for the formatting and my poor english and thanks in advance!
I would handle this by checking for the value in your LOOKUPSET expression that SumLookup is summing.
I assume that your expression looks something like this:
=CODE.SumLookup(LookupSet(Fields!ProductID.Value,
Fields!ProductID.Value,
Fields!Price.value,
"Dataset2") )
Use an IIF with ISNOTHING to check for the NULL values and set them to zero:
=CODE.SumLookup(LookupSet(Fields!ProductID.Value,
Fields!ProductID.Value,
IIF(ISNOTHING(Fields!Price.value), 0.00, Fields!Price.value),
"Dataset2") )
The function returns a Decimal datatype. By a Decimal datatype Nothing and 0 are the same. You can test this.
Put a tablix into your report with year from 2017 to 2019. Then put the year in a column of the tablix as a number format, then write the following expression in the detail textbox:
=CDec(IIF(CDec(Fields!Year.Value) = 2017, 0, Nothing))
After executing your report you will notice that every value in the year column is 0.
The same goes for the check. Both of these expressions will always return Yes. I basically check for 0 and the second one for for Nothing:
=IIF(CDec(IIF(CDec(Fields!Jahr.Value) = 2017, 0, Nothing)) = 0, "Yes", "No")
=IIF(CDec(IIF(CDec(Fields!Jahr.Value) = 2017, 0, Nothing)) = Nothing, "Yes", "No")
But remember your textbox/column has the be a number format.
So if you want to return Nothing and you display it in a number format textbox, it will show you a 0.
I have a dataset created from an expression that takes parameters from 3 other datasets.
I need to add a parameter to this that allows the user to input a value, and then the dataset will add that value to the where clause to filter the results displayed. If the value "Any" is input then the results will be unfiltered for this section of the Where clause (If that makes sense).
I wrote this and added it to the expression Where clause, but it is not working.
+ IIf(Parameters!RCode.Value = "ANY", "", " AND h.rcode = " + Parameters!RCode.Value + " ")
I can provide the rest of the where clause if it is needed, but if i remove this line, the whole thing works, if i add this line, it bombs out with
An error has occurred during report processing. (rsProcessingAborted)
Cannot set the command text for dataset 'DS'. (rsErrorSettingCommandText)
In the dataset query you can use parameter names by simple prefixing them with # eg. #RCode
To make it work, your WHERE clause should be look like (I assume your column name is rcode):
WHERE ....
AND (#RCode = 'ANY' OR rcode = #RCode )
For multivalue parameters
WHERE ...
AND ('ANY' IN (#RCode) OR rcode IN (#RCode) )
I'm trying to compare 2 rows of data in the form of %'s. I generate and it "#Error".
=IIF(Fields!Grade.Value = "ONGRADE" > LookupSet(Fields!Grade.Value = "ONGRADE", Fields!grade.Value = "ONGRADE", Fields!grade.Value = "ONGRADE", "Previous3Week"), "UP" ,"DOWN")
There are two DataSets.
You are using IIF incorrectly. IIF just looks at a comparison and returns the first value if TRUE and the second value if false.
=IIF(1 = 2, True, False)
Which reads as
If 1 = 2 then return TRUE else return False
You are also using LookUpSet incorrectly. The first LookUpSet argument is your current dataset field that you want to compare, the second argument is the field from the first that you want to compare to - since your using the same dataset, they might be the same. The third LookUpSet argument is the field that you want to return (you know the ONGRADE field, what value do you want back?).
Your expression reads, if Grade = ONGRADE > LookupSet(blah blah) ...
What is the value field that you want to compare? Assuming it's Fields!GRADE_VALUE.Value, your IIF might be like
=IIF(Fields!Grade.Value = "ONGRADE",
IIF(Fields!GRADE_VALUE.Value >
LookupSet(Fields!Grade.Value, Fields!grade.Value, Fields!GRADE_VALUE.Value", "Previous3Week"),
"UP" ,
"DOWN"),
"Not ONGRADE")
If you want all GRADE types (not just ONGRADE) compared, it would be simpler:
=IIF(GRADE_VALUE > LookupSet(Fields!Grade.Value,
Fields!grade.Value,
Fields!GRADE_VALUE.Value,
"Previous3Week")
, "UP"
,"DOWN")
I have a table in ssrs 2008. This table has a row visibility expression like:
=IIF(max(Fields!VExpected.Value) <> "", 1, 0) +
IIF(max(Fields!MExpected.Value) <> "", 1, 0) +
IIF(max(Fields!PExpected.Value) <> "", 1, 0) = 3, false, true)
Sometimes the datasource returns no data, or the returned data is not matching with this expression. In this case what I see is that a table with borders and column names but no data on it like:
id Vex Mex Pex
However, I want to show it as
id Vex Mex Pex
- - - -
Or if possible:
id Vex Mex Pex
No Data
Another question is, is there any way to hide the complete table if there is no returning data or any matching data with the expression?
Thanks
You can use CountRows function to determine how many rows your dataset is returning. If it is zero hide the table otherwise show it.
=iif(CountRows("DataSetName")=0,true,false)
Replace DataSetName by the actual name of your dataset.
For not matching expression data you can use the this expression.
=IIF(
max(Fields!VExpected.Value) <> "" AND
max(Fields!MExpected.Value) <> "" AND
max(Fields!PExpected.Value) <> "",False,True
)
The whole expression for matching expression and no rows cases could be something like this:
=Switch(
CountRows("DataSetName")=0,true,
max(Fields!VExpected.Value) = "",true,
max(Fields!MExpected.Value) = "",true,
max(Fields!PExpected.Value) = "",True,
true,False
)
Supposing VM, ME and PE expected values are numeric type I'd use ISNOTHING() function to determine when null values are being returned.
=Switch(
CountRows("DataSetName")=0,true,
ISNOTHING(max(Fields!VExpected.Value)),true,
ISNOTHING(max(Fields!MExpected.Value)),true,
ISNOTHING(max(Fields!PExpected.Value)),True,
true,False
)
Additional you can set a message when no rows are being returned from your dataset. Select the tablix and press F4 to see properties window. Go to NoRowsMessage property and use an expression to say your users there is no data.
="There is no data."
In this cases the tablix will not appear in your report but the message you set will be rendered in the location where the tablix should be.
Let me know if this helps.
My situation is
I have a parameter, this is a list, allowing multi values. That mean the first record in the list is 'Select All'
When user select All I need to include in my report all records that match with the list plus those that are blank. (My dataset is returning these)
When user select only 1 or a few I want to include only these records. No those that are blank
My problem:
I have a filter in my dataset that evaluate a parameter in a list, but I need to add a conditional filter to include a blank records when the selection will be "Select All"
I tried to use expression but this doesn't work
Filter expression
Fields!NAME.Value in = Parameters!List.Value !!!!!!!!!!!! Work Fine
But I need to change it like as
If Parameters!List.Value = 'Select All' Then
Fields!NAME.Value in = Parameters!List.Value or Fields!NAME.Value = " "
Else
Fields!NAME.Value in = Parameters!List.Value
End
Can you give an advice who can I resolve it please !!!
I'm working in SSRS R2
Thanks!!
This worked for me
Expression: =IIF(Parameters!pLocation.Value <> " All Locations", Fields!LOCATION.Value, FALSE)
Operator: =
Value: =IIF(Parameters!pLocation.Value <> " All Locations", Parameters!pLocation.Value, FALSE)
If you use Filter on your Dataset, try this:
Expression: [NAME]
Operator: IN
Value (fx): =Split(Replace(Join(Parameters!List.Value, ","), "Select All", " "), ",")
Try to work along this path. Basically you can reconstruct the multi value items into a string with Join(), and deconstruct it again into array by using Split(); where in between, you can manipulate them, for modifying (e.g. converting "Select All" into " "), adding (imitating "OR"), or removing extra items.
There is an alternative for this.
Add one more item to the paramater dataset values say "Not Available" as Label and value with the null. then there will be no change in the stored procedure and you can retrieve the data.
If the user select the specific item then he will get those values only. If he selects all then he will get the data for the null also with the all the others.
Hope this will help
You can put the logic in just one location if you do it this way.
You filter on the parameter, unless it's all values then the filter always matches.
Just a little cleaner.
Expression: =IIF(Parameters!pLocation.Value <> " All Locations", Fields!LOCATION.Value, " All Locations")
Operator: =
Value: =Parameters!pLocation.Value