SSRS : Format (indentation) new lines in a textbox using expression - reporting-services

In SSRS, I have a textbox with value as below expression, Expression is within a single textbox and I need format the lines in that single textbox.
= "Test Example "
& vbcrlf & SPACE(10)+ "First Name," + " Middle Name," + " Last Name"
& vbcrlf & SPACE(10)+ "Address 1," + " Address 2," + " Address 3"
& vbcrlf & SPACE(10)+ "Instructions: " + " Please select your country from the list below so we can display the correct prices, delivery times and shipping costs for your shipping destination."
Current Output is:
Test Example
First Name, Middle Name, Last Name
Address 1, Address 2, Address 3
Instructions: Please select your country from the list below so we can
display the correct prices, delivery times and shipping costs for your
shipping destination.
I have to format the text to start at same point and Expected Output is below:
Test Example
First Name, Middle Name, Last Name
Address 1, Address 2, Address 3
Instructions: Please select your country from the list below so we
can display the correct prices, delivery times and shipping costs for
your shipping destination.
How can I change the expression to get expected output?
Thank you!

This is the one use for the Hanging Indent property. The trick to use a negative number to get what you want.
I'm not sure how this renders in various outputs - I think the formatting might be lost in Excel.

Related

MS Access Calculated Field - Creating dynamic expression

I need to be able to create an ID CODE from the plant name to be in the format of AAAA_AAAAAAAAA_A00000 (A for alpha). Some thing like this;
Acacia dealbata
ACAC_DEALBATA_T00001
I can do the first section using Left([FieldName],4) but the middle section I'm having trouble with as it will differ depending on the remaining number of words in the name.
Acer palmatum Atropurpureum would become ACER_PALMAATRO_T00002
Acer palmatum Dissectum Rubrum would become ACER_PALDISRUB_T00003
My attempt at the middle section is;
IIf(Len([FieldName]) - Len(Replace([FieldName], " ", "")) + 1 = 2, Mid([FieldName], InStr(1, [FieldName], " "), (9 / (Len([FieldName]) - Len(Replace([FieldName], " ", ""))))), "")
And returns the following Error Message.
The end section depends on the SUPPLIER of the image of the plant and is given a specific prefix; L, H, or R. Followed by the records autonumber in the table. This prefix is stored in another table I have called SUPPLIER.
I do not know how to collect values from fields of other tables into another so any advice on this is appreciated.
If anyone is able to help please.

Ms-Access DLookup - how to I return only records from this year?

I think this should be simple, but I've been struggling for too long.
I have a form with a bound text box which I would like to return a value it has calculated. It calls on the table 'Training' which stores the variables Client, Standard and Date. Client is a string, standard is an integer and Date is in the format dd/mm/yyyy. I would like the box to return the sum of the Standard entries for this year.
So, if we've been out to see Client A last week and done one session and been out again today and done two, the table might look like:
Client A - 1 - 01/01/2017 <br/>
Client A - 1 - 12/01/2018 <br/>
Client A - 2 - 17/01/2018 <br/>
Client B - 1 - 15/01/2018
I'd like my box to return the value '3', ignoring Client A's training last year or the training this year of any other client.
I can get the box to correctly distinguish between clients, but not between years using this code:
=DSum("[Standard]","Training","[Client] = '" & [Client] & "'")
That selects the client from the training table, based on the client record currently selected in the form. It sums all the training that client has ever had - so in the example above returns '4'.
What I am struggling with is how to restrict the year. I've tried a number of variations on:
& "Year([TrainingDate])=#" & Year(Date())
but always get either Name? or Error. What am I doing wrong?
With thanks,
Matt
Use:
=DSum("[Standard]","Training","[Client] = '" & [Client] & "' And Year([TrainingDate]) = Year(Date())")
year is an integer -- try Year([TrainingDate])= " & Year(Date())

SSRS Reporting Expression to Split Full Name Field

I've been trying to get this to behave with no luck.
The database base field only has FULL NAME field, which includes Middle initials on some cases and no middle initials in some other cases.
I've been trying to display LastName, FirstName by using this ssrs expression below: While this works in names that doesn't have middle initials or name on the field.... for those names that includes middle initials/name, we run into issues with displaying.
=Right(Fields!agent_name.Value,Len(Fields!agent_name.Value)-Instr(Fields!agent_name.Value," ")) & ", " & (Left(Fields!agent_name.Value,Instr(Fields!agent_name.Value," ")))
But it includes the Middle Initials to display first.. As an example:
If the fullname field is John S Doe, above expression displays as:
S Doe, John
What I need to display is:
Doe, John
How do I set my expression to get rid of the Middle initial/name to display?
I've done a great amount of research and tried many diff expressions but no luck.. thanks in advance.
While slightly inefficient, this is a clean way to accomplish the result:
=Split(Fields!agent_name.Value," ")(Split(Fields!agent_name.Value," ").Length-1) + ", " + Split(Fields!agent_name.Value," ")(0)
Edit: The above indeed does not work with suffixes. The expression below will remove a middle initial if its the second name and has a length of 1, which you could use in a calculated field. But it would fail for first name "Ann Marie" and the first/last swap would need to be handled separately.
=IIF(Split(Fields!agent_name.Value," ")(1).Length=1,Replace(Fields!agent_name.Value, " " + Split(Fields!agent_name.Value," ")(1) + " "," "),Fields!agent_name.Value)
The short of it is that you really would be best served handling this in code. But even so, if your fullname field is space-inclusive beyond what you want to seperate on there arises the potential for ambiguous cases, like the suffix- and initial-less "Ann Marie van Der Beek".
Try using this expression:
=RIGHT(
Fields!agent_name.Value,LEN(Fields!agent_name.Value)-InStrRev(Fields!agent_name.Value," "))
& ", " & LEFT(
Fields!agent_name.Value,
InStr(Fields!agent_name.Value," ")-1
)
It is a native SSRS solution however I recommend using custom code to get an maintainable solution.
UPDATE: Regex solution:
=System.Text.RegularExpressions.Regex.Replace(
Fields!agent_name.Value,
"(\w+)\s+(\w+\.*\s)?(\w+)",
"$3, $1"
)
Let me know if this helps.

Concatenate name fields in an Access query using IIF() without printing spaces?

First of all, I am a newbie. Please keep that in mind...
That said, I have used a simple formula to concatenate name fields in a student database in Access using a query (I am using Access 2013 but must maintain compatibility with Access 2010). It reads as such:
Student Name: IIf(IsNull([Preferred First Name]),[First Name],[Preferred First Name]) & " " & [Last Name]
Which shows the student's preferred first name and last name, or first name and last name. If it turns out first (preferred or given) is null and/or last is null, obviously it prints null where appropriate.
Example of formula output using fictional names
Well, that is where the issue comes in. As you can see in the example, one student only has first name Christine, which prints as "Christine ". Another only has last name Alexander, which prints as " Alexander". It is printing the space no matter what.
Now I now it is possible using Iif to get around this -- it's used in a sample database like so:
Student Name: IIf(IsNull([Last Name]),IIf(IsNull([First Name]),[First Name]),IIf(IsNull([First Name]),[Last Name],[First Name] & " " & [Last Name]))
I want to incorporate the "Preferred First Name" field into that formula, but I just can't wrap my head around it. It seems to work backwards from how I would say this in natural speech, and it seems to be missing values. In plain English I envision it like this:
If [Last Name] is null, print only [Preferred First Name], unless that is null, in which case print only [First Name], unless that is also null, in which case print null.
Otherwise if [Last Name] has a value, print [Preferred First Name] & " " & [Last Name], unless [Preferred First Name] is null, in which case print [First Name] & " " & [Last Name], unless [First Name] is also null, in which case just print [Last Name].
(To clarify, there are sometimes cases where we are unable to get a student's full name, so I can't simply make all fields required, which is why I want to make sure it prints correctly regardless of what data is available.)
I apologize if this is too simple a question for this site, but it seemed like the best place to ask. Thank you for any help.
You want to use the Trim function. So, your string would look like:
Student Name: Trim(IIf(IsNull([Preferred First Name]),Trim([First Name]),
Trim([Preferred First Name])) & " " & Trim([Last Name]))
Trim each individual field (just in case the data got entered with an extra space or 2, which happens occasionally), and then trim the entire resultant string to get rid of any spaces as well.

How to format NUMBERS in report?

I have a calculated double Price field in my report that sometimes have a value such as 1.23456.
Each row in my report has these data: Product name followed by Price in parentheses.
=[ProductName] & ' (' & [Price] & ') '
How do I format the Price in the above expression IN THE REPORT DESIGN so that Price always has this format: 1.23? Meaning always having 2 digits after the decimal point.
Thanks. Please note I want to do this at the REPORT DESIGN, not table creation or calculation.
If you go to the Report Design view and right-click on the field that you want to format, open the properties menu.
Under the Format tab on the Properties window, there are 2 options
Format
Decimal Places
You could select Currency or General Number in the Format option and put 2 in the Decimal Places option.
Based on your edit you might be able to do the following, I haven't had a chance to test this.
=[ProductName] & ' (' & FormatNumber([Price], 2) & ') '