Dynamically Add\Remove columns SSRS 2012 - reporting-services

I have SSRS report that has around 80+ columns. I have requirement where in dynamically hide\show columns in report based on user selection. I could able to do it by setting expression for "Visiblity" property and having report parameter thro' which columns to display can be choosen.
My problem is 2 points
fox example if columns 2 and 4 to be hidden, then there is an empty column between 1 and 3 and 5 columns. How to avoid this
When i export to PDF / Excel these spaces prevail.
Let me know your suggestions / help.

You can create a query that pivots your data, so that instead of a return table like this:
ColumnName0, ColumnName1, ColumnName2
Value[0][0], Value[0][1], Value[0][2]
Value[1][0], Value[1][1], Value[1][2]
You could format it like this
ColumnName, Value0, Value2
ColumnName0, Value[0][0], Value[1][0]
ColumnName1, Value[0][1], Value[1][1]
ColumnName2, Value[0][2], Value[1][2]
And then your first column (ColumnName) would always be your title, and you could use it as your column group. You might have to use a dynamic query for this, but it would take care of both items 1 and 2 in your question.

Actually I solved my issue with following URL
http://bhushan.extreme-advice.com/conditionally-setting-column-visibility-in-ssrs/

Related

How to get total from another tablix column? (SSRS)

Hello awesome people of stackoverflow!
I need help with a simple problem with my SSRS expression.
How could I do this in SSRS?
As you can on the 2nd table below in my excel screenshot.
for each row we divide -BC5...-BC10 to column/row BC4. To get the desired results for table 2 in excel column total 2018 into column/rows BC17 upto BC22.
I've tried referencing my textbox like this
ReportItems!TextBox1.Value / ReportItems!TextBox2.Value.
But got me the wrong values.
Can someone please help.
Thank you!
If those two tables are in the same table/tablix then it should work with the expression that you wrote (try to type it instead of copy paste sometimes that may work).
=(ReportItems!Textbox7.Value /ReportItems!Textbox1.Value) * 100
If they are not in the same Table/Tablix then you should write like the following:
=(Fields!ColumnName1.Value / Fields!ColumnName2.Value) * 100
Format your cells.
There is not enough info to give you an exact answer but you should be able to work it out.
The first thing you need to do is get the context of the aggregations you want to work with. So click on the cell containing the number you want to divide ([Sum(DiscountOERestated)] ). In the row and column groups panel near the bottom on the screen, look at the row group that is highlighted. For this example I'll assume the row group is called grpCategory.
Now we need to do the same for GrossCatalogRestated. However, GrossCatalogRestated in the top tablix does not appear to be an aggregate. I'll assume it should be the total GrossCatalogRestated for the dataset. For this exmaple, we'll say the dataset name is dsMyDataSet. If it's within a row group, just swap the dataset name out with the row group name that it sits in, just like we did for DiscountOERestated .
So you expression would look something like
=SUM(Fields!DiscountOERestated.Value, "grpCategory") / SUM(Fields!GrossCatalogRestated .Value, "myDataSetName")
This will give you a deicmal result, somehting like 0.025 . You then just need to set the format property to say, "p1", so it shows as 2.5%
If this does not work, edit your question to show the expressions in the cells you are working with along with the rowgroup and dataset names.

SSRS 2012 csv export - dynamic column header name

I need to export my SSRS report to csv format. Issue I am facing is that few column header names change with country code (parameter) and I want to show the same name in my exported csv. I have gone through other related questions and topic, specifically this one. It suggested that there is a work around by setting data value to null. I have tried this by adding columns and hiding these based on country code, along with setting data value to null for that dataset field. But it did not work. I still get the hidden column in my export, with no values in it.
Can someone confirm that this workaround works or is there any other way apart from creating different reports for each country?
UPDATE: (added report screenshot and description for clarification)
Based on apporoach I have taken,
I need to only show Column 'Town' for Country A and only 'Suburb' for Country B. This is easily done by hiding columns based on Country Parameter( and works fine for EXCEL export), but when exported to CSV, both columns are exported.
UPDATE 2
Found this link which is similar to what I have been trying to figure out and looks like there is no solution which can be achieved using only one report.
According to this post
MSDN Social: Hide CSV columns conditionally in SSRS report
The XML and CSV renderers use the DataElementOutput property to
control visibility. We can select which item we want to hide in the
report, and set the “DataElementOutput” property with value “NoOutput”
to work around the issue.
Alternatively, we can add below expression to control the item’s
visibility. Please refer to the expression below:
=IIF(Globals!RenderFormat.Name="CSV",True,False)
This, incidentally, is the second answer in the thread that you posted. That answer links to the following article which explains how to do exactly what you need
Hide/Show Items Dependant On Export Format
UPDATE
It appears that you cannot programmatically set DataElementOutput for CSVs. However, according to this post SSRS - Programatically controlling the DataElementOutput property
in RS 2005 / 2008, you should be able to get the desired effect by adding a filter on the tablix directly (in addition to the visibility condition):
Filter expression: =(Parameters!DataPeriod.Value = "DAY")
Filter operator:    =
Filter value:     =true
Thereby, for the cases where the tablix is not visible, you are also filtering out all the data.
You may be able to show/hide country specific columns this way instead.
My approach would be to do this in SQL. I'm not sure how you determine which Countries require the town to be returned and which require the suburb to be returned but here's a couple of approaches that hopefully cover your scenario.
In either case, the idea is to return the town/suburb data in the same column and then an additional column that will contain a a caption that we can use as the column header.
a. Only one of either the town or suburb column in your table is populated. In this case it's pretty simple.
SELECT
Country
, ISNULL(TownOrCity, StreetSuburb) AS TownSuburb
, CASE WHEN TownOrCity IS NULL THEN 'Street-Suburb' ELSE 'Town-City' END AS Caption
FROM myTable
b. You know upfront which Countries require what and you can pass a parameter in to get the correct column. In this example we'll use a parameter called #TS and pass in either a T or and S
SELECT
Country
, CASE #TS WHEN 'T' THEN TownOrCity ELSE StreetSuburb END as TownSuburb
, CASE #TS WHEN 'T' THEN 'Town-City' ELSE 'Street-Suburb' END AS Caption
FROM myTable
Whichever approach we take you will end up with a simple table
Country TownSuburb Caption
Testland TownA Town
Testland TownB Town
Testland TownC Town
In you report, you don;t need to do anything except make the town/suburb column caption an expression something like =FIRST(Fields!Caption.Value)
That's it, the report is now nice and simple and should export without any issues.
UPDATE to method:
--
-- Dump data into a temp table
--
SELECT
Country
, CASE #TS WHEN 'T' THEN TownOrCity ELSE StreetSuburb END as TownSuburb
INTO #t
FROM myTable
--
--rename the column
--
DECLARE #NewColumnname sysname = CASE #TS WHEN 'T' THEN N'Town-City' ELSE N'Street-Suburb' END
EXECUTE tempdb..sp_rename N'tempdb..#t.[TownSuburb]', #NewColumnname, 'COLUMN'
--
-- finally get the result
--
SELECT * FROM #t

Totals in Matrix in SSRS

data in SSRS shows like this as below using the Matrix -
Can someone please help me how to get the totals for BB-1,BB-2 ,AC-1 ,AC-2 below for all the countries.I am using the running value function between the dates Aug-2015 and Jan 2017 for Columns BB-1,BB-2,AC-1,AC-2.
Type A always belong to BB-1 & BB-2. Type B belongs to AC-1,AC-2.
row groups-
Country
Type
Column Group
Date
It sounds like you want to create a secondary matrix that displays the information with a different grouping entirely. It is possible to have two matrix/tables that use the same data, and that's how I would go about solving this.
Amend the report design to the following:
Amend you report design, underneath main report add in another row group [Names], adjacent below, along with a sum(Value) field to look like this:
Report should like this:
Amend the report design to the following:

how to seperate one matrix into showing data for this year and previous

I have a report where my source gives me data for multiple years. In my report data I have 2 parameters- 1 is Brand and 2 is Year. I have made one matrix which has 5 columns in it with a row group. I want to define the column in such a manner where i pass a year to the parameter say 2016, but it automatically returns me data for that and previous year.
I tried using expression in the column group header:
=MAX(Parameters!Year.Value) OR MAX(Parameter!Year.Value) - 1
and
=MAX(Parameters!Year.Value) OR MAX(Parameter!Year.Value) - 1
Image of what I currently have:
What I want to see it as:
EDIT:
Dataset Sample:
You can exclude of your tablix the values you don't need to show.
Go to Tablix Properties window / Filters tab.
In expression use something like this:
=Switch(
Parameters!Year.Value = Fields!Calendar_Year.Value, "Include",
Parameters!Year.Value-1 = Fields!Calendar_Year.Value, "Include",
true,"Exclude"
)
Select Text and Operator select =
In Value use this:
="Include"
If you set Calendar_Year in the column group it will works.
Let me know if this helps.

Control Column Visibility using DataSet values

My client wants to be able to show/hide columns in a report based on a Parameter (ReportType). The report columns are static, they will just be controlling which ones are hidden/shown which creates a different "View" of it. Currently there are only 2 views, but we are about to add several more.
At the moment column visibility is controlled by simple expression: =Parameters!ReportType.Value = "SOMEVALUE"
and only 1 report type hides columns so this expression is fine.
Now we're moving into a situation where a column may be hidden in multiple ReportTypes and i want to avoid getting into: IF report type = VAL1 or VAL2 or VAL3 THEN HIDE as it will make it very hard to see for any given ReportType what columns are meant to be shown (as all the logic is in each column visibility expression)
I found a post and used the basic elements of it:
http://sql-bi-dev.blogspot.co.uk/2010/10/displaying-dynamic-columns-in-ssrs.html
What im trying to do is define a Dataset, something like:
SELECT * FROM
(
select 'Rpt Type1' ReportType, 'Units' ColumnName UNION
select 'Rpt Type1' ReportType, 'Price' ColumnName UNION
select 'Rpt Type2' ReportType, 'Units' ColumnName
) ReportColumns
WHERE ReportType = #ReportType
And then in the Column Visibility expression check to see if the column name exists in the dataset. This way visible columns for a report type are defined in a single place and are easy to manage/maintain.
In the post i linked, hes getting the user to select the Column names in a parameter. I want to lookup the Names in my dataset based off the ReportType param thats selected.
Im stuck on getting the column names into a parameter and then using that in the column visibility expression. Any help would be much apreciated :)
Doh, i was pretty much there.
I created a parameter and set its default values to "Get From Query" and selected my dataset and ColumnName field... job done!
Then i was just writing visibility expressions for each column using the code in the article i was following.