SSRS collapse empty field and collapse space also - reporting-services

My problem in SSRS: address lines 2 and 3 have no data
Pit ltd.
230 Sunset Blvd.
Field: Address Line 2
Field: Address Line 3
Singapore
Solution should be:
Pit ltd.
230 Sunset Blvd.
Singapore
How can I collapse these fields and also save space?
Edit: Alle these fields have to be single fields placed on the canvas. I cannot use a table due to different formattings for the fields.

You can add a visibility expression for the rows. You can also do this at a group level. Right click and go to row visibility.
Select "Show or hide based on an expression" radio button.
Click the expression button.
In the expression window, use Fields!AddressLine2.Value = NOTHING
Do the same for Address 3. Note I'm assuming your fields are named as displayed.
Update
For the same idea on a text box, just right-click the text box, go to text box properties, visibility, and use the same expression for the third option - "Show or hide based on an expression."

Related

Creating a percentage in an expression

Would like to have some text in my report like the following where the percentage is based on an expression. I would like to know how to work out the percentage.
60% of letters were sent with a first class stamp
This is an example of the figures I'm working with
First Class 300
Second Class 150
Other 50
The fields used are 'StampType' and 'RefNo'. The totals are gathered by a count on the 'RefNo'
To do this, do the following steps.
First, add a new Text Box to the report. Click inside the text box so the cursor shows inside. Right-click and choose Create Placeholder.... Enter the following expression for the Value field.
=Lookup("First Class", Fields!StampType.Value, Fields!RefNo.Value, "ReportMain") / Sum(Fields!RefNo.Value, "ReportMain")
This assumes the dataset name that is returning your data is named ReportMain. Change this if needed.
This looks up the First Class RefNo value from the dataset, and then divides that by the total of the RefNo in the dataset.
Go to the Number section of the dialog, change the Category to Percentage. Adjust the Decimal places to your liking. Click OK.
Type the text you want to follow that value after the placeholder (not in the placeholder) in the text box. Like this:
Preview the report, and you should have what you need.

SSRS Report Builder 2012 - How to hide list based on field value?

I'm using Report Builder 2012 to create a report. I have inserted multiple text boxes and other controls inside a list box so that I can hide all the controls at once just by hiding the list box. I'm using a SQL Server stored procedure to fetch rows of data. I'm using below expression to hide/show the list box.
=iif(Fields!certificateType.Value = "CT", False, True)
It works fine but it only checks the first row of data. If certificateType field is "CT" in the first row of data, it shows the list box but it doesn't hide the list box back for the next row of data in which certificateType is not "CT". It seems like list box visibility only checks the first row of data and applies it for all the other rows as well. How can i check the visibility of list for all the data rows?
Okay, based on our chat I have updated this solution.
I mocked up some data that looks like this:
certificateType
---------------
AT
BT
CT
DT
ZT
I created a quick and dirty report with a list. In that, I added a rectangle with a textbox in it. I set the dataset for the list to the main dataset (DataSet1 in my case). I set the expression for the textbox to this:
=Fields!certificateType.Value
Image in design mode:
I clicked on the list, and in the Row Groups pane, I right-clicked the Details rows, and chose Group Properties. On the General section, I clicked Add to add a new group expression. Then I chose certificateType from the dropdown.
I moved to the Page Break section of the Group Properties dialog and ticked the Between each instance of a group check box. Click OK.
Now, the report will break for each instance of a certificate type that comes in the dataset. So, if you have ten different cert types in the data, you will get one page for each.
You can't see it in my image below, but there are 5 pages now.
Hope this helps!!

Access 2007 reports, hiding fields?

I have a report in Access 2007 thats populated with data from SQL SERVER (running on a vb6 application). This report has two subreports that display data. The first Subreport has a Label, "CHILDREN" and the subreport next to it displays Names of children. The 2nd subreport has a Label "PETS" and the subreport next to it displays PetName, and TypeOfPet. In most cases there are pets in every family, however, for some clients, there are no pets. What I'm trying to do is make the label PETS invisible if there are no pets, so the Label is not on the report by itself. How would I go about doing that?? Is this something I have to code?
The following link shows how to hide the label if no data: https://forums.techguy.org/threads/solved-access-2003-hide-field-labels-on-reports-when-value-is-null.660825/
Below are the steps required:
1. Delete the label from the text box.
2. Add new text box in place of the old label.
3. Format the new text box same as other label.
4. Set it's "Can Shrink" property to "Yes".
5.Bind the 'new' label to an expression that will solve to "" if the [Pet] field is blank or to the text string "Pets:" if the [Pet] field is not blank.
6. Change text box Control Source field on the Data tab of the Properties window. In it put:
iif(isnull([Pet]),"","Pets:")
This will put a zero-length string into the text box when the [Pet] field is null and the text "Pet:" when it is not null
7. If the field is blank, it could be null or a zero-length string (""), or could have any number of blank spaces in it. Rather than use "IsNull", use a combination of functions that will solve. i.e.:
Iif(trim(nz([Pet],""))="","","Pets:")

SSRS validating parameters and stopping report

So I have two combo boxes, box1 and box2. The requirement from within SSRS is if box1 is selected set Box2 to None and if box2 is selected then set box1 to none. Now I don't think this is possible because you can only cascade parameters in one direction. Otherwise you get forward dependencies are not valid.
But the question becomes can I validate the boxes when they click View Report to display a msgbox saying Please either choose box1 or box 2 but not both
Note: I am still working in 2005.
As far as I know, View button code cannot be accessed. As a workaround, you can do the following:
Add a textbox in your report and let the text be something like "Please enter either cmb1 or cmb2" .
Now from the Database check if both Values are entered. If yes, just return the columns in your select statement as NULLs or specify a value e.g. EMP_NO = 9999.
In your report if the returned value for EMP_NO is 9999 by checking FIRST(fields!xx.value ) = 9999 you can determine what did the user enter.
Add an condition to the textbox visibility checking if the value is 9999 or not, do the same for other items in the report to hide them and just show the textbox.
This can be used for other validations as well.

SSRS - How to build a simple multi-column report?

I am using SQL Server 2008 and I want to show 1 single field from a table in multiple columns in the report. Just like if I were to print labels. How can I achieve this?
Example:
Instead of printing:
Names Report
Andrea
Austin
Barbara
Bob
Bruno
Cathy
Chis
...
I want to print in columns (say 3 fixed columns):
Names Report
Andrea ---- Bruno ---- Darren
Austin ---- Cathy ---- Francis
Barbara ---- Chis ---- Gabriel
Bob ---- David ---- Gerald
....... ---- ....... ---- .......
Edit: If I run the report and click on "Print Layout" button, I can see multiple columns. Can I set this mode as default?
For Horizontal layout of labels...
One choice is to use the columns property on the report or body elements.
This doesn't always display correctly On reportviewer. I've noticed that even if it displays correctly on your IDE and when you export to PDF. In the report viewer it will display only one column. Also it snakes the labels top to bottom then left to right.
One choice is to use a matrix and group on every 3 rows (if you want 3 columns).
This one is a little complicated.
My solution of choice is to put 3 vertical lists on the page. put the same label in each list. Return the row number in your dataset. Then just filter each list on modulo 3
For example
Result set
RIndex Fname
1 abe
2 burt
3 fred
4 george
Filter expressions
list 1 -> =Fields!RIndex.Value mod 3 = =1
list 2 -> =Fields!RIndex.Value mod 3 = =2
list 3 -> =Fields!RIndex.Value mod 3 = =0
Result
Abe Burt Fred
George
The method I use is a bit similar as what Vern suggested but differs enough to make it worth mentioning here.
You can combine the ROW_NUMBER with the modulo (%) operator directly in the query to fabricate the column number in which the record should get displayed. Here's an example that generates one while taking a group into account:
declare #numberOfColumns int = 4;
select dpc.EnglishProductCategoryName, dp.ProductAlternateKey
, (ROW_NUMBER() OVER (
PARTITION BY dpc.EnglishProductCategoryName
ORDER BY dp.ProductAlternateKey) + #numberOfColumns - 1) % #numberOfColumns + 1
as DisplayColumn
from dbo.DimProduct dp
inner join dbo.DimProductSubcategory dps on dps.ProductSubcategoryKey = dp.ProductSubcategoryKey
inner join dbo.DimProductCategory dpc on dpc.ProductCategoryKey = dps.ProductCategoryKey;
To get this displayed I'm using nested tables which are then filtered on DisplayColumn.
Have a read through following article for all the details: Creating Multiple-Column Reports
Use the 'Report' menu in Visual Studio and select 'Report Properties'. You can set columns in the 'Layout' tab.
Try this msdn article about newsletter-style reports for more details: http://msdn.microsoft.com/en-us/library/ms159107.aspx
This method does have a limitation though so in some cases it might not be applicable:
Only PDF and Image renderers support
newsletter-style reports.
EDIT:
So one approach is to use multiple tablix with a filter that checks RowNumber and accordingly displays particular records in each table.
The other way is called Newsletter-style report (link). This formatting is retained only when report is exported as PDF or Image. It can be previewed only when you select 'Print Layout' on the Preview tab in Visual Studio. Here is an example:
Create a new report with the foll. dataset: SELECT ID,NAME FROM TABLENAME
Add a new table to the report and select the ID and Name as columns
Click on the tablix and press F4 to edit the tablix properties. In the properties window, change the Size - set the width to 2in
Click on the report area outside the report page boundary and press F4 to edit the report properties. In the properties window, change the Column value to 3, and column spacing value to 0.1
On the report scroll to the right hand side, you will notice that there are 2 new columns (so totally 3 columns on the report - because you selected 3 in step 4 above). Now click on the margin at the start of the column 2 and pull it further to the left to bring it as close to the column 1. This is only to reduce the need for huge page size.
Right click on the report area outside the report page boundary and select Report Properties. Change the Page Size - Set the width to 10in
Preview the report. Now select the 'Print Layout' tab to see the result. This formatting is retained only when report is exported as PDF or Image.
As noted in points 5 and 6 - since the report body flows into multiple columns, you must ensure that the page size is at-least equal to -> ([Original report body size times the number of columns] + all the column spacing values). Otherwise it will look messy.