How to align each string in text in field column of ssrs - reporting-services

I have a field like this in the column field in ssrs.
QUINIDINEssssssssssssssssssssssssssssssssssssssssssssssssssssss GL INJ 80MG/ML
FLECAINIDEssssssssssssssssssssssssssssssssss TAB 50MG
TAMBOCORsssssssssssssssssssssssssssssssssssssssssssss TAB 50MG
and how can i align align like this...
QUINIDINEssssssssssssssssssssssssssssssssssssssssssssssssssssss GL INJ 80MG/ML
FLECAINIDEssssssssssssssssssssssssssssssssss(emptyspaceeeeeeeee)TAB 50MG
TAMBOCORsssssssssssssssssssssssssssssssssssssssssssss(emptyspa)TAB 50MG
each part of string align properly...
Any help...

Well, there are two ways to do this that I worked out, and neither is particularly elegant so I'd be surprised if someone doesn't have a better solution.
"t.a" in the code below is your table and column.
The SQL way:
SUBSTRING(t.a,1,CHARINDEX(' ',t.a,1))+REPLICATE('_',20)+REVERSE(SUBSTRING(REVERSE(t.a),1,CHARINDEX(' ',REVERSE(t.a),1)))
Change the value being replicated above from '' to ' ' and you are in business. I left it as '' to illustrate what it's doing.
The SSRS way, which is better from a DB standpoint:
=Mid(Fields!a.Value,1,InStr(Fields!a.Value," "))+StrDup(20,"_")+StrReverse(Mid(StrReverse(Fields!a.Value),1,InStr(StrReverse(Fields!a.Value)," ")))
This is precisely the same formula, executed by SSRS instead of by SQL Server.

I once used Switch to append spaces to a column field, like in the following example:
=Switch(LEN(Fields!FamilyMemberName.Value) = 1, " ",
LEN(Fields!FamilyMemberName.Value) = 2, " ",
LEN(Fields!FamilyMemberName.Value) = 3, " ")
But I didn't have to bother about the expression getting longer, since I know exactly how many spaces I should append and it wasn't more than 15.
You could use Switch in your case too or you could write a VB function in the Code tab of Report Properties window and pass the values, use some loops to generate the spaces you require.
Or it's much easier in MS SQL, all you got to do is append SPACE(NoOfSpacesInInteger) to the field.

Related

SSRS Expression - #Error in an obviously correct expression

I have an SSRS expression with this in it:
=IIF(
Fields!CUT.Value.ToString().Length > 1
,IIF(
Fields!CUT.Value.ToString().Contains(","),
Fields!CUT.Value.ToString().Substring(0, Fields!CUT.Value.ToString().IndexOf(",")),
Fields!CUT.Value.ToString()
)
,""
)
Translation:
If the field contains a ,, Get me the substring of the field from the first position to where the , is. If the field does not contain ,, just get me the entire field.
Probelm:
I get a #Error in all the pages where there is NO COMMA. If there is a COMMA, it works as expected. One of the fields, the value is 4. In a different scenario, the value is 17/64" Corrugated. I get an error for both of those.
What I've tried:
I've tried a few different approaches:
Used LIKE instead of Contains
=IIF(
IsNothing(Fields!CUT.Value)
,""
,IIF(
Fields!CUT.Value LIKE "*,*",
Mid(Fields!CUT.Value, InStr(Fields!CUT.Value, ",") + 1, (LEN(Fields!CUT.Value) - InStr(Fields!CUT.Value, ",") - 1))
Fields!CUT.Value
)
)
I added a new field to my dataset that replaces , with XXXX. I thought, maybe SSRS is not able to understand that I am talking about a , as a part of the string. And then changed the query to see if there is an XXXX in it. Still got the same #Error
Delete the .data file, cleaned the project, and rebuilt the project. Because, this is so obviously not incorrect. So I thought maybe it is not looking at the latest version of the report.
Nothing seems to do it! I am really close to doing something bad! This thing is driving me insane.
Questions:
Anyone see anything wrong with either of my expressions?
Is there a better way to do to what I am trying to accomplish? If there is a ,, give me everything before the ,. If not, give me everything.
Edit 1:
Worth noting that, in a different field, I am doing something very similar to this:
IIF(
IsNothing(Fields!CUT.Value)
,""
,IIF(
Fields!CUT.Value LIKE "*,*"
," | Length: " & Mid(Fields!CUT.Value, InStr(Fields!CUT.Value, ",") + 1, (LEN(Fields!CUT.Value) - InStr(Fields!CUT.Value, ",") - 1))
,""
)
)
What this is doing is, if there is a , in that very same field, get me everything AFTER the , and append it to | Length:. If there is no ,, just show an empty space "". This works perfectly fine. In situations where there is a , and where there is NO ,. So I've concluded that Microsoft is using SSRS to make me go crazy.
You could do this using SWITCH and test for no comma first but there is a much easier way assuming you only ever want to get the first part of the string up to the point of the comma.
This just uses the split function and takes the first element.
=(Split(Fields!CUT.Value, ",")).GetValue(0)
Nice and simple :)

Inside bracket values goes to negative when getting a csv output - ssrs 2008

I have a matrix in ssrs 2008 and have an expression in one of its columns like:
= Fields!Name.Value & "(" & Fields!Score.Value & ")"
This is working fine and bringing the values inside the brackets like Jack(7.04) or John(6.39). Name is a nullable value, so if it is null then the value for this cell is simply like (7.23) or (6.11). My problem is that when I run the report and take the output as a csv files, the data who has NULL as their names are all converted to negative values without brackets in the output file like -7.23 or -6.11. I would like to see them like on the report output, (7.23) etc, on the csv file as well.
Current csv output
Jack(7.04)
John(6.39)
-7.23
-6.11
What I want
Jack(7.04)
John(6.39)
(7.23)
(6.11)
Note that it is working fine for pdf or excel outputs, it is only happening for csv outputs. How can I fix it? Any help would be appreciated.
Edit: It seems like it is happening because of '(' character. It is working when I use another, like '['. But I am supposed to use normal brackets '(' and ')'.
it's just a comment i don't have enough reputations to make comment.
Here are couple of thoughts.
1. Did you try with the text box properties
(Text box properties -> Number -> Negative numbers)
2. Try with if statement or switch statement=iif(Fields!score.Value>0,Fields!Name.Value & "(" & Fields!Score.Value & ")","(" & Fields!Score.Value & ")")

Conditional concatenation breaks if value is nothing

I'm trying to concatenate a string on the end of a sum, but if the sum is nothing, it breaks. It seems like this is due to SSRS evaluating both conditions of the IIf statement, but I can't figure out how to get around this.
I've got....
=IIf(IsNothing(Sum(Fields!Work.Value)), "", Sum(Fields!Work.Value).ToString + " J")
Which will print out the work summary + " J" if there is one, and #Error if not. What's the SSRS workaround?
Update / Clarification
The report in question is grouping on dates and then summing up Work, so it's not the case that Work is null, per se, but that for this particular date for this particular user, there are no rows in the group.. So, there are no rows to sum up in the error causing instance.
Sample Data Set
Name Date Work
Andy 12/1/15 511.30
Andy 12/1/15 549.70
Drew 12/2/15 484.80
Drew 12/2/15 322.36
Sample Report (current)
Name 12/1/15 12/2/15
Andy 1061 J #Error
Drew #Error 807.16 J
Sample Report (expected)
Name 12/1/15 12/2/15
Andy 1061 J
Drew 807.16 J
Have you considered doing the two parts of your desired output in two different expressions in the same Cell?
I assume for the current structure you have used a matrix, with Rows for the Name, and Columns for the date. You can the set the Data to be Sum of Work, as shown here, and in the red text in the image below.
=Sum(Fields!Work.Value)
You then then right click the cell and select "Create Placeholder" to insert a second expression in the same cell.
Set the value of this expression to be as shown here, and in the blue text below
=iif(Sum(Fields!Work.Value) > 0, " J", "")
Then when the report is run, it will always show the Sum if there is one, and if the value of the Sum is greater than zero, it will also display the J as required.
Hopefully this is the behaviour you require. Please let me know if you require further assistance with this solution
Try this:
=IIF(SUM(IIF(Isnothing(Fields!Total.Value),0,Fields!Total.Value)) = 0,
"",
SUM(IIF(Isnothing(Fields!Total.Value),0,Fields!Total.Value)).ToString + " J"
)
Let me know if this can help you
IIF does not short-circuit so this #Error is from SSRS trying to use the ToString function on NULLs.
The workaround is to add another IsNothing check in the false section before using ToString:
=IIF(IsNothing(Sum(Fields!Work.Value))
, ""
, IIF(IsNothing(Sum(Fields!Work.Value)), "", Sum(Fields!Work.Value)).ToString & " J")
To solve this exact problem, because if there is no Work to display then the report should display nothing, instead of using the IIf statement with concatenation, it is simple and sufficient to set a conditional visibility on the cell.
In the cell, use the expression:
Sum(Fields!Work.Value).ToString + " J"
Then for the same cell, select:
Text Box Properties > Visibility > Show or hide based on an expression
and enter:
=IsNothing(Sum(Fields!Work.Value))
While this solves this specific problem, if the solution requires the empty cell to display anything other than blank, then the original IIf short-circuit issue is still an issue.

Display all SSRS report field values without line breaks

I have an SSRS report with a dataset that I cannot modify. I can only change the report's format.
I am trying to figure out how to have one of the reports fields display its many values inline in a list or csv fashion. Right now it prints a value and does a line break, then the next value and another line break, and so on... I would like my values to print without the line breaks.
I've tried using the Replace function in an expression (replace vbcrlf with ", ") with no success...
You're not quite providing enough information to reliably answer the question. Most likely, your question is a duplicate of this question, and my answer there will answer your question as well. The basics are:
Create a multi-value parameter #MyParameter
Set the default values for the parameter to be retrieved from your dataset
In your textbox use the expression =Join(Parameters!MyParameter.Value, ", ")
Same disclaimer holds here as well: if there are a lot of values this solution may not work very well.
It sounds like you just want an expression to remove the line feed characters in your source data so that it prints on one line. You'll probably need a bit of trial and error to work our what the characters actually are but you probably want to start with replacing:
vbCrLf
vbLf
vbCr
More on replacing line breaks in this question
You could create a Code function in the report to do the replacing, similar to the answer in this question.

How to display a sub-set of the selection of a multi-valued parameter in a text-box in SSRS

I have a multi-valued parameter called Faculty on a report. I want to display the selection in a textbox at the top of the report. The obvious solution would be:
JOIN(Parameters!Faculty.Label,", ")
The problem that I am having is that the first option in the list (the default) is "All Faculty". This is distinct from the "Select All" checkbox that SSRS provides. We have created this hardcoded "All" option because it looks cleaner on the parameters screen (the user sees "All Faculty" instead of "Adam, Arbor, Altman..." etc.). If the user leaves this checked and makes any other selections, we assume that they meant to only select the other items and the stored procedure ignores the "All" selection.
So I would like to display something like this:
IIF(Parameters!Faculty.Value(0) = "0000000", [*display all selections except value 0*], (JOIN(Parameters!Faculty.Label,", "))
The section in square brackets is what I am having trouble with. The 0000000 value represents "All Faculty".
Answered by OP in comments to original question:
I ended up using substring. In case anyone else reading this needs the
final code, here it is:
IIF(Parameters!Faculty.Count < 6,
IIF(Parameters!Faculty.Value(0) = "0000000",
IIF(Parameters!Faculty.Count = 1, (JOIN(Parameters!Faculty.Label,";
")), (JOIN(Parameters!Faculty.Label,"; ").Substring(13))),
(JOIN(Parameters!Faculty.Label,"; "))), "Multiple")
I added a check so
that it will only display up to 5 at a time, otherwise it says
"Multiple". I did Substring(13) because "All Faculty; " is 13
characters including spaces.
The solution above worked initially, but failed when the string was
less than 14 characters (due to the IIF). You set me on the right
track and I came up with a fairly elegant solution:
Switch(Parameters!Faculty.Count > 5, "Multiple Selected",
Parameters!Faculty.Count <= 5,
Replace((JOIN(Parameters!Faculty.Label,"; ")),"All Faculty; ",
""))'code'