SSRS How to change grouping and columns by using parameter - reporting-services

My goul would be to implement a parameter #Grouping with two possibilities: Vendor / Product
With the parameter I need to change the grouping of my data, not only in calculateing the data but also in the sorting of the columns:
Do I need to use executable SQL and calculate everything outside the report and use dynamic columns like "Column1=Vendor, Column2=Product if Parameter=Vendor" to place them in the Tablix?
Or is it possible to manage all this in the report using grouping properties? If so, unfortunately I am not very familiar with the grouping expressins and would thank you for detailed answers.

I was able to use the parameter :)
With Vendor beeing my default first Group, I made a Right-Click on the Group in the GroupingBox. In the General section I added an Expression on the "Group on":
=IIf(Parameters!Grouping.Value = "Vendor", Fields!Vendor.Value, Fields!Product.Value)
On the child group Product I did the opposit:
=IIf(Parameters!Grouping.Value = "Vendor", Fields!Product.Value, Fields!Vendor.Value)
The same expressions I used in the Sorting section. And also in the fields on the Tablix.
Thank you.

Related

ssrs Summing two fields same dataset, different tablix

I am trying to sum two same fields, from two different Tablix's.
Both Tablix's filter for different building names. "Mydata" is the name of my dataset.
=Sum(Fields!TotalFloorArea.Value,"Mydata") +Sum(Fields!TotalFloorArea.Value, "Mydata")
How do I reference the different Tablix?
Many thanks in advance.
There is more than one way to accomplish this. One approach is to use an IIf() as part of each of your SUM() calls. Using the IIf() condition(s) you will be repeating the condition(s) used to filter your two Tablix controls.
Try something like this:
=Sum(IIf(Fields!BuildingName.Value = "BLDG-A",
Fields!TotalFloorArea.Value,
0), "Mydata") +
Sum(IIf( Fields!BuildingName.Value = "BLDG-B",
Fields!TotalFloorArea.Value,
0), "Mydata")
I prefer to use Report Variables for this. Define a couple of report variables totalBuildingA and totalBuidlingB and use the expressions above for the individual variable's expressions:
totalBuildingA
=Sum(IIf(Fields!BuildingName.Value = "BLDG-A",
Fields!TotalFloorArea.Value,
0), "Mydata")
totalBuildingB
=Sum(IIf(Fields!BuildingName.Value = "BLDG-B",
Fields!TotalFloorArea.Value,
0), "Mydata")
Then you can add the two report variables together to get the equivalent result as the first example, (but with code that is a lot more flexibile for combining the SUMs for two or more other Building Names etc):
=Variables!totalBuildingA.Value + Variables!totalBuildingB.Value
I got this to work now. I added a row Outside the group below then added Totals into Rows. Then for grand total I referenced the textboxes for example Reportitems!Textbox22 + Reportitems!Textbox23.
I'm not sure this makes sense. But now working! Just trying to work out the final formulas.
Referring to textboxes can get messy. And there's no direct way to reference sums from other groups or tables. A good option that will work for this is to add calculated fields to your dataset. You can have one for the 1 building value and another for the other 25 buildings. The expression would look something like this:
=IIf(Fields!BuildingName.Value = "BLDG-A", Fields!TotalFloorArea.Value, Nothing)
That way you can sum those calculated fields from anywhere in the report. You don't need to specify the scope in your Sum function, let it use the current scope for the cell like this:
=Sum(Fields!BldgA_TotalFloorArea.Value)

SSRS expression issue using iif function

I have a data set that is returning two properties, a name and a total units. I am trying to set an iif expression on a data bar where iif(field!Name.Value = "Name", field!Total.Value, 0)
this is not working I get an error of rsFieldReferanceAmbiguous, the fields refers without specifying a dataset aggregate. And the only option that it gives me as an aggregation is First, but I do not want to get the first name, I want the bar to display the total units base on the name field that is in the iif expression.
rsFieldReferenceAmbiguous refers to trying to match something that is not in local scope. Therefore you have to aggregate it. You are probably wanting something like this:
=Sum(IIF(Fields!Name.Value = "Name", Fields!Total.Value, 0))
The function you are trying to use would be better suited to a calculated field in your dataset. Then you can just refer that that field in your report. This allows you to filter the data line by line instead of by groups.
Right-click on the dataset and go to Dataset Properties.
Go to Fields.
Click Add then Calculated Fields.
Enter the name of the field and then the expression here.
Make sure your tablix has the dataset specified under General -> DataSetName on the properties pane. If you have more than one data set on the report you will need to specify which data set your reffering to like so:
(Fields!Name.Value, "NameDataSet")
If your useing tables you may need to ckeck if you have grouping and if so how your grouping your data.

SSRS: how to group by multiple parameters

I need to create a report using SSRS, it needs dynamicly group by the matrix.
I added a parameter(name: ColumnData) for it and the available value like 'Date', 'Type', 'ServerName',
for a single value, I can edit the group by expression to
=Fields(Parameter!ColumnData.Value).Value
but when the parameter is multiple, Parameter!ColumnData.Value would return a list and I need to use like that:
==Fields(Parameter!ColumnData.Value(0)).Value & Fields(Parameter!ColumnData.Value(1)).Value
but it's not what I want as I need to indicate the index manually...
Anyone knows how to use the multiple parameters in the group by expression?
Thanks a lot!
If you deselect 'Allow multiple values' in the Parameter properties, your group by expression should work as is.
You will then be able to group by the selected value from the parameter.
(It will then not be possible to choose more than one of the values).
But it only makes sense to group on one value, or?
I stumbled on this topic, but my solution was simple. I had to group by multiply fields, and ended using something like this:
<GroupExpression>=Fields!ColumnName1.Value</GroupExpression>
<GroupExpression>=Fields!ColumnName2.Value</GroupExpression>
<GroupExpression>=Fields!ColumnName3.Value</GroupExpression>
But this may not be what you are looking for since you wanted something more generic.
You can check this answer as it has some advices about matrix:
Multiple group expressions in list (ssrs 2005)
Hope that helps.

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

Suppress the duplicate values in group, SSRS Reports

I have an SSRS report
where the date should be grouped by project category
the project code in the category is repeating in side the group how do I suppress the value
Please help me to get an idea.
Thanks,brijit
You can also hide fields by putting an expression in the Hidden property like this:
=Fields!ProductCode.Value = Previous(Fields!ProductCode.Value)
So if the value in the previous record is the same as this one, it will hide the field. You must sort the dataset correctly for this to work. In your case I think the sorting would be Date, ProductCategory, ProductCode.
In the past I used this often together with expressions for field borders to group the output visually.
I think there is one option hide duplicates in properties in ssrs. so you will check in that option under the project category group.so that you can hide the duplicate values and get unique records. first u create one group based on project category in fields properties and then check in that hide duplicate option under that group.whenever you check in that option it will high light one drop down list showing containing group or dataset there you select your created group.
This is a bit late for you brijt, but what I do is edit the textbox properties for that field, in the font tab enter an expression for Color as follows:
=IIf(Fields!ProductCode.Value = Previous(Fields!ProductCode.Value), "White", "Black")
...assuming your background is white this will effectively do what you want.
I think it may be an issue concerning the way you are grouping the dates. Do you have the grouped with time on them as well but suppressing the hours in your output?
For example:
12-5-2010 12:00:00
12-5-2010 13:00:00
if you strip the times off in how you see them but not how you group them, they would show up duped.