I have an address Field in my SSRS report that displays as below
PARADISE BALTI
104
WHITWORTH ROAD
ROCHDALE
LANCASHIRE
OL12 0JJ
How do I format this so it all appears on one line?
For this you have to write expression and concatenate string like
=First(Fields!Name.Value, "DataSet") + "<br/>" + First(Fields!Address1.Value, "DataSet") + "<br/>" + First(Fields!City.Value, "DataSet") + ", " + First(Fields!State.Value, "DataSet") + " " + First(Fields!Zip.Value, "DataSet")
Take a text box and create a placeholder and set value as an expression shown above.. Then choose markerup type as HTML ...
Related
I am trying to pass a hyperlink in SSRS to open a new SSRS report (in pdf) from a text box. It is currently set up and works passing a single parameter :
="http://servername/ReportServer_REPORTS16/Pages/ReportViewer.aspx?%2fdummy%2fDocuments%2fCertificate+of+Insurance+Issued&rs:Command=Render&PolicyNo="
& Parameters!PolicyNo.Value &"&rs:Format=PDF"
However when I add in the second parameter :
="http://servername/ReportServer_REPORTS16/Pages/ReportViewer.aspx?%2fdummy%2fDocuments%2fCertificate+of+Insurance+Issued&rs:Command=Render&PolicyNo="
& Parameters!PolicyNo.Value &"&
Entitled="&Parameters!Entitled.Value &"&rs:Format=PDF"
I get an error message :
The ActionInfo.Action.Hyperlink expression for the text box
‘Textbox48’ contains an error: [BC30277] Type character '&' does not
match declared data type 'Object'.
I've gone through every similar error I've found on google but cant work out where im going wrong.
You need to convert all your values to strings then use the + operator....
Here'a an exmaple from one of my reports that does the same thing.
=IIF(Fields!PackSizeDesc.Value = Nothing, Nothing,
"http://MyServername/ReportServer?/Brand+Value/_sub+SKU+Price+Details"
+ "&CountryID=" + cStr(Fields!CountryID.Value)
+ "&CategoryID=" + cStr(Fields!CategoryID.Value)
+ "&RecordedPeriodID=" + cStr(Parameters!PeriodID.Value)
+ "&TMB=" + cStr(Fields!TrademarkBrandID.Value)
+ "&PriceStage=" + cStr(IIF(Fields!IsActualprice.Value = 1, 10, 11))
+ "&pm=" + cStr(Fields!PackMaterialID.Value)
+ "&pt=" + cStr(Fields!PackTypeID.Value)
+ "&ps=" + cStr(Fields!PackSizeID.Value)
+ "&psu=" + cStr(Fields!PackSizeUnitID.Value)
+ "&upp=" + cStr(Fields!UnitsPerPack.Value)
+ "&rc:Parameters=Collapsed")
Note: The first line just disables the link if there is now value in a particular column. This does not render to PDF but that's not part of your issue.
I have this string that is coming from the db and the words are separated by a space. the number of words can vary from a minimum of one to a maximum of six, so what i essentially want is to start a new line immediately after the second word.
For example the string "Natural Financial Services" needs to show as:expected result
in the report. i case if there is only one word then there should not be any line break, i have tried this Replace(Fields!CustodianNameTxt.Value," ",Vbcrlf) but this will cause each word of the string to appear in a separate line, like this:result with my current expression
Which is not what is expected, anyone please suggest if there is any solution to achieve this?
Thanks in advance.
Select report properties -> Code
Add this function (there might be better ways of achieving the same in VB, this is just one example):
Public Function splitline(byval line as string) as string
dim words() as string=line.split(" ") ' separate the lines into array of words
dim pos as integer ' to calculate the position for the breaks
dim newlines as string = line ' string for the line with added breaks
if words.length > 2 then ' there are 3 or more words add break after second word
pos=len(words(0)) + len(words(1)) + 1 ' this will be the position of the first break
newlines=newlines.remove(pos,1).insert(pos,VBCRLF) ' remove the space and add a break
end if
if words.length > 4 then ' there are 5 or more words add break after forth word
pos=len(words(0)) + len(words(1)) + len(words(2)) + len(words(3)) + 4 ' adding 4 because 2 spaces + cr + lf
newlines=newlines.remove(pos,1).insert(pos,VBCRLF) ' remove the space and add a break
end if
return newlines
End Function
The expression in the will then just be:
Code.splitline(Fields!CustodianNameTxt.Value)
One way it can be done is by splitting the string into an array of words and then rebuilding it with the added CRLF using choose function
In this example, the choose are inside an isnothing to cater for lines with less than six words:
=IIF(not isnothing(choose(1,split(Fields!CustodianNameTxt.Value," ")))," " + choose(1,split(Fields!CustodianNameTxt.Value," ")),"")
+IIF(not isnothing(choose(2,split(Fields!CustodianNameTxt.Value," ")))," " + choose(2,split(Fields!CustodianNameTxt.Value," ")) + Vbcrlf,"")
+IIF(not isnothing(choose(3,split(Fields!CustodianNameTxt.Value," ")))," " + choose(3,split(Fields!CustodianNameTxt.Value," ")),"")
+IIF(not isnothing(choose(4,split(Fields!CustodianNameTxt.Value," ")))," " + choose(4,split(Fields!CustodianNameTxt.Value," ")) + Vbcrlf,"")
+IIF(not isnothing(choose(5,split(Fields!CustodianNameTxt.Value," ")))," " + choose(5,split(Fields!CustodianNameTxt.Value," ")),"")
+IIF(not isnothing(choose(6,split(Fields!CustodianNameTxt.Value," ")))," " + choose(6,split(Fields!CustodianNameTxt.Value," ")),"")
I'm trying to join two strings but I want them to be divided by a break line.
This is my code:
<td>#(string.Join("<br /> ", report.TimeReportProjects.Select(x => x.Project.ProjectName)))</td>
<td>#(string.Join("<br /> ", report.TimeReportProjects.Select(x => x.Description.Shorten(35))))</td>
<td>#(data.StartHour + ":" + data.StartMinute.ToString("00") + " - " + data.EndHour + ":" + data.EndMinute.ToString("00"))</td>
<td>#(Math.Floor(hours) + ":" + TimeSpan.FromHours(hours).Minutes.ToString("00"))</td>
The "br/>" tag will just be read as a string which is not to strange I assume, I know if i want to mix html code in a code block I should use #: but I am not sure how to use that in this case.
There is a Html.Raw method that should help you. It can be applied like so:
<td>#Html.Raw(string.Join("<br />", report.TimeReportProjects.Select(x => x.Project.ProjectName)))</td>
I have an SSRS report that takes 2 optional text parameters as below:
StartDate, Text, allow Null, format YYYYMMDD
EndDate, Text, allow Null. format YYYYMMDD
I am trying to format a header text box that will show the below:
If the parameters are Null, then I would get by default the Month Name and the Year (as the report will get data defaulted to the previous Month)
If the parameters are set then I want to format them as dd MMMM YYYY (so 20141103 will be formatted as 03 November 2014
Here is the code I am trying to use for the Expression in the text field:
= IIF(IsNothing(Parameters!StartDate.Value),
" for " & MonthName(Month(DateAdd("m",-1,Today))) & " " & Year(DateAdd("m",-1,Today)),
"From " &
RIGHT(Parameters!StartDate.Value,2) + " " +
MonthName(Month(
LEFT(Parameters!EndDate.Value,4) + "-" +
MID(Parameters!EndDate.Value,5,2) + "-" +
RIGHT(Parameters!EndDate.Value,2)
)) + " "
+ LEFT(Parameters!StartDate.Value,4) +
" to " +
RIGHT(Parameters!EndDate.Value,2) + " "
+ MonthName(Month(
LEFT(Parameters!EndDate.Value,4) + "-" +
MID(Parameters!EndDate.Value,5,2) + "-" +
RIGHT(Parameters!EndDate.Value,2)
)) + " " +
LEFT(Parameters!EndDate.Value,4))
so as you can see, if the parameter is Null (allowing for the report to default to run the last months data when scheduled) then the function should just show something like December 2014 but if they are entered as YYYMMDD then I need to format them.
I am getting the below error (in SSRS in Visual Studio 2013):
[rsRuntimeErrorInExpression] The Value expression
for the textrun ‘Textbox15.Paragraphs[0].TextRuns[0]’
contains an error: Conversion from string "--" to type 'Date' is not valid.
I have also tried using CDate around
LEFT(Parameters!EndDate.Value,4) + "-" +
MID(Parameters!EndDate.Value,5,2) + "-" +
RIGHT(Parameters!EndDate.Value,2)
(these should come out as 2014-11-01 for example) but again, no luck
So where am I going wrong here and how can I format those dates if they are entered?
I would use expression something like this:
=Format(CDate(Left(20150131, 4) + "-" + Mid(20150131, 5, 2) + "-" + Right(20150131, 2)), "dd MMMM yyyy")
I believe it is better to use integer or date parameters rather than text parameters. So you could convert date text parameter to date before it appears in the report by doing something like:
select cast('20150131' as date)
I am writing an SSRS report in which my client wants the report header to contain the criteria on which the report is based (actually, this is the report variables, such as date).
I tried to do this with textboxes, but can't seem to position the textboxes in such a way that upon export to excel there aren't crazy cell merges.
I also tried to do this with a table in the report body, but got the variable added to each line of the report.
I don't see a position property, as if I was working in just a web form, but am at a loss as to what to do. Any suggestions? Thanks!
Cell merges are a fact of life when exporting to Excel unfortunately, that's how the report rendering engine tries to maintain fidelity with the original report design. The best way to minimise this is to ensure the edges of the report elements align with each other as much as possible, so that the renderer can align the report without having to merge cells.
What you are doing by putting textboxes in the report header to display the value of selected report parameters is a good approach that is commonly used, so keep experimenting with the layout to get it to align correctly.
If you can describe what is happening when you export the report in a bit more detail I might be able to offer some more advice.
In my reports, I add an additional table at the end of the report and assign a page break before the tablix. In the large, single-cell table, I write sentences using quoted text, built-in fields, and parameter values to list all of the parameter information. I label the Name of the Tablix "Parameters" so when the report is downloaded, all of the parameter data goes with it in a nice, non-invasive format. When troubleshooting reports this has proved very valuable.
Here's an example:
=Globals!ReportName + " run by " + User!UserID + " on " + FormatDateTime(Globals!ExecutionTime, DateFormat.ShortDate) + ". "
+ vbcrlf +
"Parameters: " + "Program ("+Parameters!BusinessEntityID.Label+ "), Deliverable Status Code (" + Join(Parameters!DeliverableStatusCode.Label, ", ") +
"), Science Area (" + Parameters!ScienceAreaID.Label + "), Thrust Area (" + Parameters!ThrustAreaID.Label + "), Center (" + Parameters!CenterID.Label + ") "
+ IIF(Parameters!TaskActiveFrom.Value is Nothing, "", ", Tasks Active between "+ FormatDateTime(Parameters!TaskActiveFrom.Label, DateFormat.ShortDate)
+ " and " + FormatDateTime(Parameters!TaskActiveTo.Label, DateFormat.ShortDate))
+IIF(Parameters!TaskStartFrom.Value is Nothing, "", ", Tasks Started between " + FormatDateTime(Parameters!TaskStartFrom.Label, DateFormat.ShortDate)
+ " and " + FormatDateTime(Parameters!TaskStartTo.Label, Dateformat.ShortDate))
+ IIF(Parameters!DeliverablePlannedFrom.Value is NOTHING, "", ", Deliverable Due Date between " + FormatDateTime(Parameters!DeliverablePlannedFrom.Label, Dateformat.ShortDate)
+ " and " + FormatDateTime(Parameters!DeliverablePlannedTo.Label, Dateformat.ShortDate))
+ IIF(Parameters!DeliverableExtendedFrom.Value is Nothing, "", ", Deliverable Revised Due Date between " + FormatDateTime(Parameters!DeliverableExtendedFrom.Label, Dateformat.ShortDate)
+ " and " + FormatDateTime(Parameters!DeliverableExtendedTo.Label, Dateformat.ShortDate))
+ IIF(Parameters!PublicationReceivedDateFrom.Value is NOTHING, "", ", Publication Received Date between " + FormatDateTime(Parameters!PublicationReceivedDateFrom.Label, Dateformat.ShortDate)
+ " and " + FormatDateTime(Parameters!PublicationReceivedDateFrom.Label, Dateformat.ShortDate))