SSRS Sorting and Renaming an Empty String - reporting-services

I'm building a bar chart that has many values and one of the values is an empty string. When added in SSRS, the blank string returns a '1' value (The first bar on the chart). How do I change the name from '1' to Blank? Also, how do I sort an Blank string within the chart?
Here's what I tried on changing the name to 'Blank' and it doesn't seem seems to be working:
=iif (IsNothing(Fields!AGE.Value), "Blank", iif(CSTR(Fields!AGE.Value)= "", "Blank", CStr(Fields!AGE.Value)
Here's what I tried to sort and can't get it to work..probably because to empty string is messing me up. I'm only showing a sample below otherwise the code would be too long.
=Switch(Fields!Age.value="INCORRECT", 1, Fields!Age.value= "AO", 2,true,3)
Thanks in advance for your help!

#rajeshpanchal - thanks for pointing me in the right direction. I went back and changed my SQL query to include the empty strings within the Case statement. Something like Case when fieldname = '10' and fieldname = '' then 'Blank Profile'
Once I had the empty string named to something other than '1', then I was able to sort my chart within SSRS by creating a new calculated field and using the following Switch function:
=Switch(Fields!Age.value="INCORRECT", 1, Fields!Age.value= "AO", 2,true,3)
I then went to the chart data, right clicked on the category group and choose category group properties..then clicked on sorting and input my newly created sorting field. I was trying to get the INCORRECT bar to show first on the chart and you can see below that it worked.

Related

RDLC - Hide a table row

I have an RDLC report with a table in it. I want to hide a string column if there is no data present in any of the rows(supress if blank sort of thing). I have been googling for the last 2 hrs and trying with different suggestions but i can not make it work.
I tried the following so far.
Set the expression for the Hidden attribute of the column to
=IIf(Fields!Category.Value = "", True, False)
But it is checking only the first row but not the entire row set.
Trying to create a concatenated string with the field values, so if the final string is empty i'll hide the table column. But i can't find a way of concatenating a string column from a table. Runningtotal() works with only numbers it seems.
Can some one point me to the right direction.
initially i thought it is very easy, but doesn't seem so.
Did you try to use CountDistinct?
I think something like this should do the trick
=(CountDistinct(Fields!Category.Value) > 1) Or (Fields!Category.Value != "")
Or you can try to make a custom string aggregate function
String aggregation in SSRS 2005

Missing field formatting

I am having some trouble getting around missing fields in my report designing.
Many of the users on the database have a missing Address Line 2.
The report is being rendered using list items like this:
Name
Address 1
Address 2
Town
Postcode
So if Add2 is missing it appears like so:
Name
Address1
Town
Postcode
Is this possible using lists within Report Builder 3?
See attached image.
My recommendation would be to use row visibility to hide rows where the corresponding field is empty or missing. I don't know whether your data has "" or NULL behind the scenes so this is generic advice.
Here is a great set of examples of the types of formulae you can use:
http://msdn.microsoft.com/en-us/library/ms157328.aspx
If the field is NULL you can use the is nothing evaluator like
=(Fields!Sales.Value is NOTHING) to return a TRUE or FALSE, alternatively you can do a check of the string length using the function LEN() to see how long it is and if it is 0, hide the row.

Need Help on SSRS SPLIT function

Hi All I need your advice,
1) I have a dynamic string which changes each time.
for example today the string will be "ItemA,ItemB,ItemC" and tomorrow it will be "itemA,ItemB" only.
2) I have an SSRS report which has 3 columns
3) I want to split this string "ItemA,ItemB,ItemC" and want to show split substrings in these 3 columns of ssrs table. the Delimiter is "," (comma)
4) I had used
=Split("ItemA,ItemB,ItemC",",").GetValue(0) in the first column of the report
=Split("ItemA,ItemB,ItemC",",").GetValue(1) in the second column of the report
=Split("ItemA,ItemB,ItemC",",").GetValue(2) in the third column of the report
5) everything works fine until my string is "ItemA,ItemB,ItemC" ,
BUT WHEN MY STRING CHANGES TO "ItemA,ItemB" I am seeing "#Error" in the third column.
I understood the error, for
=Split("ItemA,ItemB,ItemC",",").GetValue(2) we don't have any value because the string now has only 2 values after applying split function.
Is there any way i can avoid #Error in the third column.
NOTE: I have to compulsorily use 3 columns in the ssrs report.
I had tried using =Replace(Split("ItemA,ItemB",",").GetValue(2),"#Error","NULL") in the third column but that also wont worked.
This is similar to the divide by zero issue in using IIF statements. The problem is that IIF is not an expression, it is a function with three parameters:
IIF(Condition, ValueIfTrue, ValueIfFalse)
Accordingly, ALL parameters are evaluated BEFORE being passed to the function, which results in the error because the erroneous expression is still evaluated even when the condition should mean that it isn't.
I can't see a way to use the usual workaround tha solves the problem in the divide by zero case. What we need is a real language that doesn't have this problem. Fortunately, this is availble in the form of custom code.
Do the following:
Right-click on an area of the report surface that has no report objects
Select Report Properties
Click on the Code tab
Insert the following code:
Public Function ExtractCode(Combined As String, Position As Integer) As String
if (Split(Combined, ",").Length >= Position) Then
Return Split(Combined, ",").GetValue(Position-1)
Else
Return ""
End If
End Function
Click OK and go back to the report
Right-click on the cell you want the expression in and click Expression
Insert the following expression:
=Code.ExtractCode(Fields!Combo.Value, 3)
The value 3 is the "column" that you want to extract from the Combo field, so to get the second "column" you would use 2. If there isn't a column at that position, an empty string is returned.
you could change the visibility of the 3rd column to hidden if the name returns an error
You can append a dummy element and then split:
yourText = "ItemA,ItemB"
item0 = Split(yourText & ",", ",").GetValue(0)
item1 = Split(yourText & ",", ",").GetValue(1)
item2 = Split(yourText & ",", ",").GetValue(2)
item0 = ItemA
item1 = ItemB
item2 =

SSRS Reports - Formatting Date Column using expression

I am using SSAS cube to display data in my report. There is a date column in the cube which may be blank. If it is blank I need to display blank otherwise I need to format it as "MM-yyyy". I am using the below mentioned expression in the column.
=IIf(Trim(Fields!Chargeoff.Value) = "", "",
Format(CDate(Fields!Chargeoff.Value), "MM-yyyy"))
The rows which have date values are perfect with the correctly formatted date being displayed. However for blank rows, it displays error saying
The Value expression for the textrun ‘Chargeoff.Paragraphs[0].TextRuns[0]’ contains an error: Conversion from string "" to type 'Date' is not valid
I tried with IsNothing, Null and everything else that came to my mind but could not get to display blank.
Does anyone have any suggestions on how to do this?
Update
I actually formatted my date in SSAS instead of SSRS.. That did the trick for me..
=IIF(CDATE(IIF(TRIM(Fields!RequiredStart.Value).ToString().Length = 0,
"1/1/0001",
Fields!RequiredStart.Value)).ToString() = CDATE("01/01/0001"),
"",
Format(CDATE(IIF(TRIM(Fields!RequiredStart.Value).ToString().Length = 0,
"1/1/0001",
Fields!RequiredStart.Value)), "dd-MMM-yyyy"))
:)
try putting and Empty Date in for the output instead of an empty string. 00-0000 it is looking for a Date and you give it an empty String. I would imagine that you either have to give it an empty date or a Default Date

SSRS expression editor does not recognize embedded code function

I have an SSRS report with information about invoices my company has issued with things like amount, date, payment, amount due, etc. I'm using SSRS 2008 (not R2) in Visual Studio 2008 environment. My issue has to do with formatting the report using the Expression editor. Currently, an invoice will be formatted as silver if the invoice has an Amount Due (a column) over 0.01 (outstanding invoice). We also issue credits (negative amounts) and these are almost always the negative amount of a previous invoice.
So, an invoice that has a credit issued to it will still show as silver because it's amount due > 0.01. But if there is a credit issued to this invoice, it's not actually outstanding and should be white. For example, if an invoice is $100.00, and there is a credit after for ($100.00), the original invoice's background color should be switched to white.
Here's where the code explanation comes in. I thought this was possible with custom VB code in the report, but it seems like the Expression editor in SSRS will not recognize my function as it says "Unrecognized identifier". I googled this a bit, and most of the topics I came across said that it will show that but actually work anyway. Well, I'm pretty sure it's not working at all, because I put this in as my expression and got all white cells for a certain column:
=IIF(Fields!Amount_Due.Value > 0.01,
IIF(Code.HasCredit(Fields!Amount_Due.Value) = True, "Blue", "Silver"), "Red")
The HasCredit function is below.
Function HasCredit(ByVal currentAmt as Double) As Boolean
Dim i as Integer
Dim amt as Double
Dim amts as System.Collections.ArrayList = New System.Collections.ArrayList()
Dim negativeAmt as Double
Dim retValue as Boolean = "False"
i = 0
For i = 1 to Report.Parameters!Test.Count()
amt = Report.Parameters!Test.Value(i)
amts.Add(amt)
Next
negativeAmt = currentAmt * -1
If amts.Contains(negativeAmt) Then
retValue = "True"
End If
Return retValue
End Function
When these two pieces are run, I get white background for all cells of this column. I read something on the net saying that only Shared functions would work, but I found multiple other examples showing functions that were not shared that worked. When I make it shared, it gives me: BC30369 Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class. due to the Report.Parameters!Test.Count() line. I got the idea for using Report.Parameters from http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/a7d59224-0ee5-491e-883b-2e5fcb3edeab.
So to reiterate, what I'm basically trying to do is get the values of each cell in this column into a collection and, for any two amounts where one amount has a negative equivalent, give it a white background instead of silver.
In SSRS 2008 R2, even if you reference a valid custom code method, the expression editor may still warn that the identifier is invalid. This does not always mean that it's invalid. My function worked even though that warning was thrown.
After a bit more researching I figured out how to solve this. I basically had to add a textbox with the =Join() function so that all the values in a column were put in this textbox; then reference the textbox in custom code and use a boolean value in the expression editor. Detailed instructions below.
1) Add a multi-valued parameter to your report (Right click Parameters, Add Parameter). Name it, select Allow Multiple Values, select Hidden for parameter visibility. For Available Values tab, select Get values from a query. Point to your dataset, and set the Value field to the column you want the parameter to check. For me that was my Amount Due column. Label field is irrelevant and can be left blank. In the Default Values tab, do the same, make sure the value field is set to the same column as before. Under Advanced, select Never refresh.
2) Create a new textbox on your report. Might want to name it, ex txtColumnValues. Edit the expression and put this in: =Join(Parameters!YourParameter.Value, ",") This will get all of the field values from the column you specified in your parameter, each separated by a comma.
3) Edit your report's custom code and make a VB function (as Boolean) to check the textbox. For example here is my code.
Public Function HasCredit(Amt as Double, ri as ReportItems) as Boolean
Dim retValue as Boolean = False
If Amt > 0.00 AndAlso ri!txtAmounts.Value.Contains(Amt*-1) Then
retValue = True
End If
Return retValue
End Function
4) Finally go to your expression editor for the field you want to change. In my example I wanted to change the background color if the current field had a negative equivalent in one of the other fields (my textbox), so my code looked like this:
=IIF(Fields!Balance.Value > 0.01
AND Code.HasCredit(Fields!Balance.Value, ReportItems) = False, "Silver", "White")
I had to take separate pieces of info from 3 or 4 pages, put them together, and hope they worked... after about a week they did... I guess it's all about persistence. If you need any further help with this just let me know.