Link to home
Start Free TrialLog in
Avatar of CarlaGibson
CarlaGibsonFlag for United States of America

asked on

Dynamically Remove a Group without removing data

My data has a column for Sales Person and one for Customer.  I need to be able to dynamically group the report by just Customer (alphabetically) or by Sales Person and then Customer.  I added 2 groups, a parent group for Sales Person and Child group for Customer.  If I hide the Sales Person group with a parameter, nothing shows on the report when it should just show the list of Customers.  

How can I achieve this?  (I'm using SSRS 2008)


Sales Person    Customer
-------------------------------------------
Person A            Customer 1
Person A            Customer 3

Person B            Customer 2

- or -

Customer
---------------------
Customer 1
Customer 2
Customer 3


Avatar of Nico Bontenbal
Nico Bontenbal
Flag of Netherlands image

The trick is not to hide the Sales Person group based on the parameter, but to change the grouping based on the parameter. So for the "Group on" property of the Sales Person group you use an expression instead of just the Sales person field. The expression would be something like this:
=iif(Parameters!GrouponSP.Value ,Fields!SalesPerson.Value,1)
I haven't tested it so it might need a little tweaking, but I hope you get the idea. I assumed the parameter is GrouponSP and the Salesperson field is SalesPerson. Based on the value of the parameter this expression will return the Sales person or always 1, that last resulting in no grouping.
Next step is to hide the SalesPerson column based on the parameter, but since you know how to hide the group, I assume you know how to hide the column.

This technique can even be expanded so the user can select from a list of fields, the field to group on.
Avatar of CarlaGibson

ASKER

Thanks for your help!!

I already tried that.  The grouping works fine like that, but the 'Column Visibility' option is disabled.  So when I do that, I have a blank column.  Is there another way to hide the column if 'Column Visibility' is disabled on the right click menu?  (I'm new to SSRS.)  I'm using a tablix.

1. Create GRoup for Sales Person (Order by Sales Person)
2. Details have Sales Person, Customer (Report order by Customer)
The report has to group by customer as well as sales person since it summarizes other items.
Please first try PatelAlpesh's suggestion. But if that doesn't help take a look at the example in this post. I think this does exactly what you asked for.
The example doesn't need a table in the database, but you need to change the data source of the data set of course.
I don't know why your 'Column Visibility' option is disabled. Might be because you have merged cells. Or because I used 2008 R2. Or it is because of this:
http://www.sqldev.org/sql-server-reporting-services/how-to-disableremove-a-group-based-on-a-parameter-18635.shtml
(search for the part that starts with: "This was easier in SSRS 2005")
If you can't hide the column. Maybe you can set the width to 0 and get almost the same result.
Sorry forgot the attachement. It's not allowed to upload an rdl. So I renamed it to .xml. Please rename it back to .rdl
DynamicGroup.xml
Nicobo, That is exactly what I am looking for.  But in your rdl file, you use the 'Column Visibility' option to hide SalesPerson.  My 'Column Visibility' is disabled for all columns.  This report will be exported to Excel.

Here's a screenshot of my report.  

Is it possible that I set up the tablix wrong?  Although I'm not a novice programmer, this is my first time using SSRS.  I have plenty of experience using Crystal Reports 8.5.
ReportScreenshot.JPG
Nicobo, I think I figured out why your tablix is different than mine.  I have dynamic columns in the details as well as dynamic rows.  When I added a dynamic column to your report, it disabled the 'Column Visibility' option.
Did you try already to use an expression for the width of the column. You could set this to 0 to hide the column. Might not be 100% what your are looking for, but might be good enough.
Where do I find the column width expression?  All I could find was a size and there was no expression option.
ASKER CERTIFIED SOLUTION
Avatar of Nico Bontenbal
Nico Bontenbal
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It worked!!  Thank you!

I had read that paragraph several times and never really understood what it was saying.  Thank you for clarifying.
Thank you so much!!