stuck in microsoft report - ms-access

My report is containing some null value.
Report is generated through query
In my report I am calculating sum of every field for that I had written =iif((field name) is null,0,sum(field name))
Through this function I am getting result as 0 only if field contains some value as well

I agree with Remou, you should be using the footers for totals. However if you wanted to carry on with the way you are doing things then try replacing the IIF with NZ(MyField,0)

You should put that IIf statement in the query for that (or those) fields that you want to avoid nulls on. That way you can just put the Sum function in the details section of the report with impunity (assuming details section here).

Related

How to apply multiparameter to ssrs report filter

I have a master that can be filtered using 4 different parameters. I used a iif statement to join all the parameters to filter the report.
The problem I am now having is when more than one paramater is selected, it tends to return values for the first parameter rather than for all
My paramter expression is as follows:
expression
iif(IsNothing(Parameters!Div.Value)=0,Parameters!Div.Value
,iif(isnothing(Parameters!St.Value)=0,Parameters!St.Value
,iif(isnothing(Parameters!Sp.Value)=0,Parameters!Sp.Value
,Parameters!Hc.Value)))
values
=iif(IsNothing(Parameters!Div.Value)=0,Parameters!Div.Value
,iif(isnothing(Parameters!St.Value)=0,Parameters!St.Value
,iif(isnothing(Parameters!Sp.Value)=0,Parameters!Sp.Value
,Parameters!Hc.Value)))
Any help will be helpful
I think what you are trying to do is something like this:
=IIF(NOT ISNOTHING(Parameters!Div.Value), Parameters!Div.Value,
IIF(NOT ISNOTHING(Parameters!St.Value), Parameters!St.Value,
IIF(NOT ISNOTHING(Parameters!Sp.Value), Parameters!Sp.Value,
Parameters!Hc.Value)))
Do you only want to check for one value?
I usually check each parameter separately so it uses all of them at once. Though there may be a situation where your theory is what you want.
If you want to evaluate all the parameters, just add them to the FILTER of the dataset, table, or group. Choose your field in the Expression and the Parameter in the Value.

SSRS Filter with a different column from a different dataset

I want to filter my column, let's call it AllStudentID from dataset1 with another column from a different datset.
Dataset1 had many column such as AllStudentID, Class, Time, Location.
Dataset2 has other columns but i'm focused on a similar column called OnCampusID.
I've tried looking into using a filter but since the report itself has the columns from Dataset1, i run into an issue where if I select the column in dataset2, it always gives a First(OnCampusID). And I don't want that.
I looked into IIF() but again, i'm using a column from a different datset plus if let's say that they are NOT equal, I don't want to display anything, instead of putting something there. I know that you have to put a result if true and a result if false.
If I"m thinking of it in terms of SQL statements, it's like having a WHERE clause WHERE AllStudentID=OnCampusID.
I tried running a Parameter but I don't want the select part on the top but rather have the report filtered already.
Am I missing something? I know it has to be simple.
Mind you, the following example above is just an example i made up, not the real thing.
Assuming that each OnCampusID only appears once in Dataset2 then you can do a Lookup expression to filter it:
=IIF(IsNothing(Lookup(Fields!AllStudentID.Value, Fields!OnCampusID.Value, Fields!OnCampusID.Value, "Dataset2")), False, True)
If OnCampusID appears more than once in Dataset2 then do the same thing using LookupSet.
To get the graduate field from Dataset2 just to a Lookup in the Value of the cell, like so:
=Lookup(Fields!AllStudentID.Value, Fields!OnCampusID.Value, Fields!Graduate.Value, "Dataset2")

Adding Fields into an expression in an SSRS 2008 report

Thank you in advance for taking your time to answer my question.
I am having trouble with expressions in the SSRS reporting system.
The Field I am adding required fields from the dataset I provided in the report, however when I try to preview the report I get the Following message:
"A Value expression used for the report parameter ‘Policies_Total’
refers to a field. Fields cannot be used in report parameter
expressions."
This is my expression:
=IIF(Sum(Fields!policy_id.Value, "DataSet1") Is Null, 0, Count(Sum(Fields!policy_id.Value, "DataSet1")))
That was suppoed to be converted from Crystal reports which has the following expression:
If IsNull ({usp_rep_agent_cases;1.policy_id}) then
0
Else
Count ({usp_rep_agent_cases;1.policy_id})
Any help is much appreciated.
Thank you
I think it may be as simple as understand that a 'parameter' should be passed into SSRS before fields are created for the most part. If this parameter is DEPENDENT on the value of something else first being chosen you cannot list it first as the field is not yet populated to my knowledge. It appears you are trying to use an expression to count something from a field from a dataset when you just make a dataset and reference that field directly. So instead of trying an expression you may choose a few other options instead:
Choose on the left pane of your parameter 'Available Values' selected 'Get values from a query'. You may use your query which is a 'dataset', value is self explanatory, label is what the end user will see display.
The option 'Allow null' value will accept a null value
You may run into situations where multiple datasets may need to be used, multiple selects or querying objects. In my experience with SSRS it gets mad at times when you try to reference a dataset used to display data with a dataset used to determine an event or action. SSRS also gets relativity slower the more Expressions you do so doing a whole report with nothing but expressions versus taking the power of the built ins of the RDL language is not really worth it IMHO.
For SSRS expressions you need to use IsNothing for NULL checking, something like:
=IIF(
IsNothing(Sum(Fields!policy_id.Value, "DataSet1"))
, 0
, Count(Sum(Fields!policy_id.Value, "DataSet1"))
)
In fact the whole expression seems a bit odd; what are you specifically trying to achieve with your expression? Are you just trying to count non-null values?
=Sum(IIf(IsNothing(Fields!policy_id.Value), 1, 0), "DataSet1")
Also, your error seems to be saying that a parameter is referencing a field when this isn't allowed, which may not be solved by changing syntax; I think more information about what you're trying to achieve is required here.

SSRS: Get values from a particular row of DataSet?

My dataset currently has 12 rows of data. Each representing data for a month. I would like to have variance of a column between to rows, the rows being last & last but one i.e., latest month and previous month's data.
It could have been simple if I were to work on tablix but thats not the case. I want those values for a textbox.
Any ideas on it anyone?
I hope you are using SSRS 2008R2:
R2 introduced the Lookup function that is perfect for this scenario.
=Lookup( Fields!ProductUID.Value ,Fields!ProductID.Value,Fields!Price.Value,"PriceDataSet")
The Lookup function above will evaluate the first parameter ("Fields!ProductUID.Value") in the current dataset, then look for a matching value in the field specified in the second parameter ("Fields!ProductID.Value") in the dataset specified in the fourth parameter. The value of the third parameter is then evaluated in that row of the dataset and returned.
A little convoluted, but very helpful.
In your case, you can use this in a textbox with a calculated a static number:
=Lookup(
Month(DateAdd(DateInterval.Month, -1, GetDate())),
Fields!MonthID.Value,
Fields!Name.Value,
"DataSet1")
This should calculate a number for last month, then look for a match in DataSet1.
In this example I have a tablix with Statecode and name as below
enter image description here
Suppose you want to display the name of state of CA, write an expression as -
=Lookup(
"CA" ,
Fields!StateCode.Value,
Fields!StateName.Value,
"ReportData"
)
This will return 'California' in the text box
I ran across this post while trying to solve a similar problem but with columns of double data type. Not sure why but SSRS did not want to return my first row using LOOKUP in combination with ROW_NUMBER in SQL(If someone can solve that all the better). I ended up using a SUM(IIF) instead. Hopefully, this is useful for someone else.
=Sum(IIF(Fields!RowNum.Value=1,CDBL(Fields!MyNumericColumn.Value),CDBL(0)))
Note: If SSRS complains about data types, just cast both parts of the IIF to the desired data type.

Adding optional filter in SSRS 2008

I am trying to add an optional filter on a text field in a report. I have tried setting it up in the dataset but it treats it as a required filter so if it is not populated, no results are returned. It needs to use the Like operator. Any advice?
As I was typing out a work-around to this problem, I realized an incredibly easy solution (now that I understand better how it works).
Here's what I did:
Since Hong pointed out that all filter conditions must be met, I reversed my thinking. I moved my existing "IN" filters to the query and fed the parameter directly to the query. Then I created by "LIKE" text filter on the report which a default value of "*" so it would immediately return everything.
Here's what I could've done:
Just the last part. Added the "LIKE" filter with a default value of "*" so it immediately returned everything.
I also agree that most of the time it's best to send the params back to SQL. Since that's not what the OP is asking, here is the best option I have found for doing this. And it is actually quite simple.
Add your parameter with the appropriate data type. Let's use the
example of a "City" in this case (a text/string field).
Check "Allow Nulls" on the parameter.
Add a filter to either a tablix, table or dataset.
In the expression, select the field you want to filter on. Select the appropriate operator, in my example of a data set with Cities, in the Value put in this:
=IIF((Parameters!City.Value Is Nothing), Fields!City.Value, Parameters!City.Value)
I don't think you can make an optional filter in DataSet Properties/Filters, adding filters there means returning results that match ALL filter contiditions, so it is "AND" logical relation among all filters, not "OR".
My sugguestion is to use filter in query designer of the dataset, where you can define "OR" relations to filter out data. For instance: Your_Text_Field="SomeValue" OR Your_Text_Field is Empty.
Although I agree that most of the time it is best to send the parameters back to the stored procedure or data layer to reduce the amount of data returned, I have a case where it is just as easy to do the parameter handling in the RDL file via a filter. Due to this unique situation I found this solution which gives you a way to create an Optional filter in the RDL file.
http://www.andrewshough.com/development/sqlserver/ssrs/optional-filter-in-ssrs/
It is a great blog post with easy step by step instructions on how to create an optional filter.
Please Note: This is NOT my blog but I though this solution was great for what I needed and I hope it helps someone else when they google for "optional filter in SSRS" like I did.
I found a post which solved my problem setting the filter for a report-consumer to a) all multivalue fields being selected so the user b) could specify his/her selection if necessary.
Kasim 8 Dec 2010 8:55 AM #
In reports when we want to default the multivalue parameter to 'Select All' following are the steps.
Open the Report parameter window from the Report menu.
Select the Report parameter from the left handside of the window.
Select 'Multi-value' checkbox and appropriate 'Available values'.
Under default values select 'From Query' radio button'.
Select the appropriate 'Dataset'.
Select appropriate 'Value Field'.
Save the Report and select Preview Tab. You will find all the items selected in the multivalue >parameter list and the result displayed for all the selected items.
found on: http://blogs.msdn.com/b/bimusings/archive/2007/05/07/how-do-you-set-select-all-as-the-default-for-multi-value-parameters-in-reporting-services.aspx
(The Post came up in the comments quite in the middle.)
You can accomplish this by using an expression on the dataset filter.
Check this