SSRS Using IIF to determine what to SUM - reporting-services

I want to SUM the Fields!DisbursementActualNetAmount.Value where the Fields!TransactionType.Value = "D" but with the code I have created I keep getting #error in the textbox for the output. What am I doing incorrectly?
=Sum(IIF(Fields!TransactionType.Value = "D", Fields!DisbursementActualNetAmount.Value, 0))

Try using the expression below to convert to decimal.
=Sum(IIF(Fields!TransactionType.Value = "D", CDec(Fields!DisbursementActualNetAmount.Value), 0))

Related

SSRS Sharepoint List IIF Field Value = "area 1" then add 60 days to date value

I hope someone can assist or point me in the right direction
I have a report that contains Fields!District.Value, If this value = "area 1" then i would like to add 60 days to the Field!Date.Value
Obligatory "I'm still learning" SSRS and I have tried the following with no success;
=IIf(Fields!District.Value="North Lanarkshire","DateAdd("d", 60, Fields!Date.Value)"
I'm assuming it's placement of a , or )
thanks in advance for your help :)
There are a couple of mistake here. Let's break it down.
To start with the IIF function syntax can be thought of like this..
IIF([Expression to evaluate to true or false], [expression to return if true], [expression to return if false])
So your first expression Fields!District.Value="North Lanarkshire" is fine, this will return true or false.
Next expression, what to return if true is close but not correct. "DateAdd("d", 60, Fields!Date.Value)". There is no need for the outer quotes and instead of "d" you should use DateInterval.Day so this should end up being DateAdd(DateInterval.Day, 60, Fields!Date.Value).
Finally we need something to return if the result is false (i.e. District is not "North Lanarkshire"). I'll assume you just want the original date column's value returned here so we can just use Fields!Date.Value
So, the final expression should look like this.
=IIF(Fields!District.Value="North Lanarkshire", DateAdd(DateInterval.Day, 60, Fields!Date.Value), Fields!Date.Value)

switch statement in ssrs

I have an SSRS report in which I am trying to hide columns based on the select value from a multi-select dropdown. I tried using multiple IIF statements as well as SWITCH CASE but it always throws an error.
Following is my IIF and CASE statements for 2nd and 3rd columns.
=IIF(Parameters!columns.Count >= 1, IIF(Parameters!columns.Value(0) = "3", true, false),
IIF(Parameters!columns.Count >= 2, IIF(Parameters!columns.Value(1) = "3", true, false),
IIF(Parameters!columns.Count >= 3, IIF(Parameters!columns.Value(2) = "3", true, false),
false)))
=IIF(Parameters!columns.Count >= 1, IIF(Parameters!columns.Value(0) = "2", true, false),
IIF(Parameters!columns.Count >= 2, IIF(Parameters!columns.Value(1) = "2", true, false),
false))
=SWITCH(Parameters!columns.Count = 1, IIF(Parameters!columns.Value(0) = "2", false, true),
Parameters!columns.Count = 2, IIF(Parameters!columns.Value(1) = "2", false, true))
=SWITCH(Parameters!columns.Count = 1, IIF(Parameters!columns.Value(0) = "3", false, true),
Parameters!columns.Count = 2, IIF(Parameters!columns.Value(1) = "3", false, true),
Parameters!columns.Count = 3, IIF(Parameters!columns.Value(2) = "3", false, true))
Please help me what I am doing wrong in here
Based on the comments, it appears you are getting an Array Out Of Bounds error which will occur when you attempt to reference a position in an array that does not exist. In this case, your multi-value parameter is considered an array and you are referencing that in the syntax .Value(0). The problem occurs because SSRS will evaluate the entire IIF or SWITCH statement at execution regardless of which value is ultimately returned. This means that when your report has less than 3 values selected, these expression will always be trying to call an array position that does not exist, resulting in the error you are seeing.
So, in order to fix this and check the values as you intend, there is actually a fairly simple workaround that should get you the correct results. The following expression uses JOIN to put all of the parameter's values into a single result with a comma delimiter. You can then use the InStr function which will return a numeric value indicating the position in a string where the search value is first found. In this case, we are searching for the value 3. If 3 is not found, the InStr function will return a value of 0 and any other value will indicate that 3 is present in the joined parameter list.
=IIF(InStr(Join(Parameters!columns.Value, ","), "3") > 0, true, false)

Using SUM with a switch function in Report builder 3.0

I have a column of data called Date and I am using that to perform a switch. Basically the figure needs to be 120 on a weekday and 0 on a weekend so I have used.
=SWITCH
(Weekday(Fields!Date.Value) = "1", "0",
Weekday(Fields!Date.Value) = "2", "120",
Weekday(Fields!Date.Value) = "3", "120",
Weekday(Fields!Date.Value) = "4", "120",
Weekday(Fields!Date.Value) = "5", "120",
Weekday(Fields!Date.Value) = "6", "120",
Weekday(Fields!Date.Value) = "7", "0"
)
Which works great. However I also want a Total at the bottom of the sheet. I (somewhat naively) tried adding
=SUM( ... )
to the expression but that resulted in an #Error in the textbox. I also tried
=SUM(ReportItems!Textbox85.value)
and that didn't even run throwing the error
The Value expression for the textrun
'Textbox84.Paragraphs[0].TextRuns[0]' uses an aggregate function on a
report item. Aggregate functions can be used only on report items
contained in page headers and footers.
So my question is how do I sum up this switch function or do I need to rethink this? I guess functionally all I really need is count of the total weekdays so far "this" month (that stays accurate no matter what month is picked using the date parameters). I can then * that number by 120.
So I came at it from a different angle and tried a SQL based solution. I added a column with the code
,CASE
WHEN
DATEPART(dw,convert(date,format(dateadd(hh,1,[Start Time]),'dd/MM/yyyy'),103)) in (1,7)
THEN 0
ELSE 1
End as [weekday]
Then used
=Fields!weekday.Value*120
in my textbox and
=Sum(Fields!weekday.Value, "DataSet1")*120
in my total. Got the desired results.

SSRS REPORT BUILDER, Comparing two diffrent data sets in one Tablix, Expression

I have two datasets and want to compare them in an expression.
I would like to do something like this:
=iif(Fields!Grade.Value = "ONGRADE" > LookupSet(Fields!Grade.Value = "ONGRADE", Fields!grade.Value = "ONGRADE" , Fields!grade.Value = "ONGRADE", "Previous3Week"), "UP" ,"DOWN")
This currently returns "Error" within the "ONGRADE" row.
you need to bind your component with one of the datasets and then accordingly you can write following expression :
=iif(Fields!grade.Value > (Fields!grade.Value, "ONGRADE_DataSet2") , "UP", "DOWN")
in this example, the component is binded with the first dataset and the second dataset is getting referred.
This may help.

Replace different values with specific text in report builder

I have a table that will return a number and i need to convert it into a text label
20 = Entered, 30 = Returned, 200 = Cancelled, 220 = Complete, 300 = Deleted
I want these to show in my report as simply 'Complete' etc.
Im able to use the replace function to get one value to show correctly in the report:
=Replace(Fields!status.Value,"220","Complete")
But i cant work out how to do this for each possible number that will show in this column
Best way would likely be modifying the query with a CASE statement as mentioned, if you are able to do that. But if not, a cleaner alternative to the nested Replaces would be to simply use a Switch statement:
=Switch(
Fields!Status.Value = "20", "Entered",
Fields!Status.Value = "30", "Returned",
Fields!Status.Value = "200", "Cancelled",
Fields!Status.Value = "220", "Complete",
Fields!Status.Value = "300", "Deleted"
)
This is not the most efficient way to do this, but it's a quick fix:
=Replace(Replace(Replace(Replace(Replace(Fields!status.Value,"220","Complete"), "200","Cancelled"),"300","Deleted"),"20","Entered"),"30","Returned")
A better way would be to modify your DataSet query to replace the numbers with a CASE statement. See this documentation:
https://learn.microsoft.com/en-us/sql/t-sql/language-elements/case-transact-sql