Im trying to create an IIF statement on SSRS where one of the results have an expression inside. I could only find examples with plain text but wanted to no how i can mix text and this expression as a result:
This is an example of what I'm trying to do:
=IIf(Sum(Fields!BytesTotal.Value, "dataset_traffic") = 0,
"No data available",
"Your data is 'Sum(Fields!BytesTotal.Value, "dataset_traffic")/1073741824'"
)
How can i declare an expression inside an IIF result?
Try this:
=IIf(
Sum(Fields!BytesTotal.Value, "dataset_traffic") = 0,
"No data available",
"Your data is " & Sum(Fields!BytesTotal.Value, "dataset_traffic")/1073741824
)
Let me know if this helps.
Related
I am trying to create an expression that checks if the condition is not correct just go to the else statement, for an easy example I did the following
=SWITCH(TRUE, "AA", FALSE, "A"/0)
=IIF(TRUE, "AA", "A"/0)
as you may guess the conditions here were set always to print (AA) but the actual result is always (#Error), how to avoid this, I just wanted it to execute if true and ignore the error in the false section.
obviously, my statement is a bit more complicated but in short, that's the situation I am in with the following code
IIF(SPLIT(Parameters!JSON.Value, chr(34) & "Text" & chr(34)).Length > 1, SPLIT(SPLIT(Parameters!JSON.Value,chr(34) & "Text" & chr(34)).GetValue(1),chr(34)).GetValue(1), "")
when there is no value it should print an empty string but it looks like SSRS looks at the true condition and prints #Error regardless of the result of the IIF true or false.
how i can avoid this, or how to check if (#Error) and print something else?
My expression is different than the ones I looked at already. MY code looks like this and I am having a hard time logically reading it. The code works but is part of another larger IIF statement that is used to filter out certain values on a given table column on the report.
I want to be able to "learn" how to read this type of IIF statement as it really does not make sense to me as written.
=IIF(Fields!DMDeptARCFlag.Value=1,
IIF(Fields!CloseFlag.Value=1,"",
IIF(Fields!ARCPaymentRequested.Value=0,"Invalid ARC Payment","")),"")
This expression is called "InvalidPaymentLoaded" and is used in the following expression
=TRIM
(IIF(IsNothing(Reportitems!WTBTIClosure.Value)=0 AND Fields!SrMgmtStatus.Value = 1 AND Fields!DMDeptARCFlag.Value = 1, Reportitems!WTBTIClosure.Value, "") +
IIF(IsNothing(Reportitems!ARCPaymentNotLoaded.Value)=0 AND Fields!DMDeptARCFlag.Value <> 1, Reportitems!ARCPaymentNotLoaded.Value, "") +
IIF(IsNothing(Reportitems!InvalidARCClose.Value) =0, Reportitems!InvalidARCClose.Value , "") +
IIF(IsNothing(Reportitems!BCDPayementNotLoaded.Value)=0, Reportitems!BCDPayementNotLoaded.Value, "") +
IIF(IsNothing(Reportitems!InvalidPaymentLoaded.Value)=0, Reportitems!InvalidPaymentLoaded.Value, "") +
IIF(IsNothing(Reportitems!InvalidMISCClosure.Value)=0, Reportitems!InvalidMISCClosure.Value, "") +
IIF(IsNothing(Reportitems!InvalidMCFClose.Value) =0, Reportitems!InvalidMCFClose.Value , "") +
IIF(IsNothing(Reportitems!InvalidDeductionClose.Value)=0, Reportitems!InvalidDeductionClose.Value, ""))
Your IIF is not that complex if you break it down....
Remember basic syntax for IIF is...
IIF([This is true], [then this], [else this])
So in you expression you have
"If DMDeptARCFlag =1 then do some more work, else return ""
=IIF(
Fields!DMDeptARCFlag.Value=1,
IIF(Fields!CloseFlag.Value=1,"", IIF(Fields!ARCPaymentRequested.Value=0,"Invalid ARC Payment",""))
,"")
If DMDeptARCFlag does equal 1 then we look at the first nested IIF which reads
If CloseFlag = 1 return "", else do some more work
IIF(Fields!CloseFlag.Value=1,"", IIF(Fields!ARCPaymentRequested.Value=0,"Invalid ARC Payment",""))
So if CloseFlag does not equal 1 then we look at the final nested IIF which simple reads
If ARCPaymentRequested = 0 return "Invalid ARC Payment", if not return ""
I think you could simplify the expression though as really you only ever return 1 of 2 values so if you work out all the conditions for returning one value you should be able to get rid of all those nested IIFs
Something like this
=IIF(
Fields!DMDeptARCFlag.Value=1 AND Fields!CloseFlag.Value <> 1 AND Fields!ARCPaymentRequested.Value=0
, "Invalid ARC Payment"
, "")
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 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