new to SSRS
I have table with column 1 is Department, and column 2 is The calculation
For example sum of the cost...
I have used the expression below to sum the cost
but I want to exclude the department that are null, but its no joy..
=Sum(IIF(Fields!ReturnOrder.Value = "1" + IsNothing(Fields!Department.Value) = 1, Fields!Cost.Value, 0))
column 1 is still showing the null department. I do not wish to show this...
I just want to have a column 1 showing the department names, that does not show the null rows.. and column 2 sum of cost where return value = 1
please help
To make your expression work the way you have it, you need to change the plus to an AND for logical operations and leave the ISNOTHING as a Boolean (without the = 1):
=Sum(IIF(Fields!ReturnOrder.Value = "1" AND NOT(IsNothing(Fields!Department.Value)), Fields!Cost.Value, 0))
I'm not sure what the ReturnOrder is for but left your condition in.
The expression you are looking for is
=Sum(IIF(Fields!ReturnOrder.Value = "1" AND IsNothing(Fields!Department.Value) = False, Fields!Cost.Value, 0))
Tip: In case your value is decimal instead of 0 use Cdec(0) to avoid errors.
To avoid displaying null departments I would suggest filtering your SQL query.
You can also do it by filtering the tablix
Expression: IsNothing(Fields!Department.Value)
Type: Boolean
Operator: Equal =
Value: False
Doing so will hide Null departments and your expression can be simplified to
=Sum(IIF(Fields!ReturnOrder.Value = "1", Fields!cost.Value, 0))
The best way is to alter your query:
SELECT *
FROM [YourTable]
WHERE [Department] IS NOT NULL;
You can also select the details row, click the Properties tab, and enter a formula in the "Hidden" property
=IIF(IsNothing(Fields!Department.value), True, False)
This says, "if department is null, hide this row, otherwise show it". The first method is better because less data is returned to your report. The second method requires that all rows are returned, and the report has to sort through which ones to show.
Select the detail row (click the three lines), select the Properties tab, and replace "False" with that formula:
Related
I'm creating a debtor invoicing report which has two parameters.
Parameter 1: This is a single value parameter called #booking_date. I filter the results(main dataset) by adding this into the query as a query parameter.
Eg. WHERE BookingDate = #booking_Date
Parameter 2: This parameter has two specified values - Yes or No. The parameter is called #live_run and the default value is 'No'. Basically, when this parameter has the default value of 'No', it does not limit/effect the results in any way. On the other hand, when this parameter has a value of 'Yes', it should limit the results by only displaying the bookings where the invoice has been paid off. There is a field I can use for this called Booking_Paid_off as follows - WHERE Booking_Paid_Off = 1.
I have parameter 1 in place, but I am unsure how to bring in Parameter 2 because it will be based on two conditions, do I need to use an If statement or a case statement? Do I need to create a new dataset for the second Parameter? I only want to limit the results with Parameter 2 ONLY if Parameter 2 has a value of Yes, otherwise I want the results to stay the same.
You have many options. You can switch out the Dataset entirely based on the parameter or use an IF inside the dataset to determine which query to run or simply check the parameter in your WHERE clause.
I recommend the latter.
SELECT
Field1,
Field2
FROM
Table1
WHERE
(
(#live_run = 'Yes' and Booking_Paid_Off = 1)
or (#live_run <> 'Yes')
)
I have an SSRS report. It has a Marks dropdown, and a resultset "Classresult". When I select any value from Marks dropdown, it filters my result for selected value and displays the result.
Say when I select "100" from marks dropdown, it filters my Classresult dataset and shows all results with 100 value.
But it doesnot show values which have NULL in marks field.(the resultset ClassResult contains NULL values.
Is there any way i can include NULL values ??
Currently my condition is:
Marks == Parameters!Marks.Value
Do you have the ability to wrap an IsNull() around the Class result field in your datasource?
Like IsNull(ClassResult,0) AS Classresult
This will replace nulls with a zero. Alternately you could replace the 0 with a different value of your choice.
Use the IsNothing() function to check for a NULL value in an SSRS expression. It returns TRUE if the value is NULL.
You can include NULL in the query that populates the Marks drop down. (If you put the available values in statically, then add it there...) but here is how you can do it in the query.
SELECT ValueField, LabelField
FROM MarksTable
UNION
SELECT '(NULL)', '--NULL--'
Then in the query whose results you are filtering add
ISNULL([Marks], '(NULL)') as Marks
We have a series of reports which return a set of values for a parameter based on the userID. This works and we're happy with the way it works.
Now we need to implement a default parameter setting. The logic being
If there is only one value in the parameters available dataset, then set that as the default.
If there is more than one value in the parameters available dataset, then leave the parameter blank.
This is what I have so far - I know I have the following issues:
-Parameters cannot read fields, therefore I need the expression to look at the dataset as a whole.
-I'm unsure what my then statement should be to allow the user to review all available values without them being selected.
=IIf(CountDistinct(Fields!storekey.Value, "UserStoreVerification")) = 1, First(Fields!storekey.Value, "UserStoreVerification")," ")
You can create a separate dataset to populate the "default values" for the parameter. In this dataset you can add logic to count the number of rows that would be returned by the other dataset that provides the parameter values. If there are greater than 1 values returned by the first query then the second dataset just returns NULL (i.e. no default values are selected).
Example
If your original dataset for parameter values (e.g. "dsParamProduct") used a query like this:
SELECT ProductNumber
FROM dbo.Product
WHERE Available = 'Yes'
Then the dataset query for the default values (e.g. "dsParamProductDefault") could be something like this:
DECLARE #ValueCount INT
SELECT #ValueCount = COUNT(*)
FROM
(
SELECT ProductNumber
FROM dbo.Product
WHERE Available = 'Yes'
) vals
IF #ValueCount = 1
SELECT ProductNumber
FROM dbo.Product
WHERE Available = 'Yes'
ELSE
SELECT NULL
Supplying "NULL" as the default value when there is more than one value will mean none of the available values are selected and therefore the user will have to manually select them (assuming that NULL isn't a valid value for your parameter - if it is then make sure the default query will return something else that is definitely not valid). If there is only one possible value then the default value query just returns the same result as the parameter values dataset, which means that the parameter value will be selected.
Set up another parameter that is dependent on the first, same type but slightly different name, and do your code at bottom with one suggested change:. Change " " at the end before the parenthese end to be 'NOTHING' instead. I believe this is interpreted by SQL as NULL which is what you want.
Now you should be getting population of the parameter so I would debug and check it by just dragging and dropping it to the design surface and it should be black if you have more than one default value. You can optionally make this parameter 'hidden' once you can confirm it works.
Now you trick your main dataset with a nifty predicate (or else use some other logic if it suits you better)
Where value = isnull(#DependentParam, value)
Basically this is stating "if the parameter is not null use it, else equate the clause to be everything as it will assume value = value".
I use the following expression to obtain a row number for a table in SSRS:
=RunningValue(CountDistinct("Table1"),Count,"Table1")
I also use an expression for the row visibility property. Lets just say that the Visibility expression is
=IIf(Fields!MyField.Value + Fields!MyField.Value <> 0, False, True)
My expression for the row number does not consider if the row is visible or not.
I could obviously change my dataset query, but is it possible to just alter my Row Number expression to only include rows that aren't hidden?
Thanks
You can probably achieve this by combining the logic of your two expressions.
Say you have a simple DataSet and a simple Tablix based on this:
Here, RowNum is calculated as:
=RunningValue(Fields!val1.Value, CountDistinct, "Tablix1")
Next, let's hide some rows using an expression based on the other two fields:
=IIf(Fields!val2.Value + Fields!val3.Value <> 0, False, True)
This breaks RowNum, but we can amend the expression to ignore the hidden rows. We do this by NULLing them out (i.e. for SSRS set as Nothing) - CountDistinct will not consider any Nothing values:
=RunningValue(IIf(Fields!val2.Value + Fields!val3.Value <> 0, Fields!val1.Value, Nothing)
, CountDistinct
, "Tablix1")
Now RowNum is ignoring the hidden rows as required:
I have a dataset called 'dsAllStuTargetData' - i'm trying to count the number of the 'A' values that appear in the column 'Target'.
I'm doing this using a textbox with an expression, I can count the total number of values using the following:
=Count(Fields!Target.Value, "dsAllStuTargetData")
However when I try to count where the value equals 'A' it doesn't work.
=Count(IIF(Fields!Target.Value, "dsAllStuTargetData")="A",1,0)
For this case you need a Sum, not a Count, i.e. something like:
=Sum(IIf(Fields!Target.Value = "A", 1, 0), "dsAllStuTargetData")
Count will just count the number of rows; the IIf doesn't do anything there - something like CountDistinct can be affected in certain cases but this will not work here.
However, Sum will take the total of all rows which meet the IIf condition, i.e. the total of all 1 values in the DataSet, which is what you're after.
IIF wants it's arguments in the format:
IIF(condition, true part, false part)
Which would equate to something like
Count(IIF(Fields!Target.Value = "A",1,0),"dsAllStuTargetData")
Does that work?