I am running a report on SSRS where 2 of the columns are running value.
Before it was like:
SO i was running the report by each code at once.
I changed it to allow multiple codes to be shown in the report (Grouping by Code) and it gave me the below:
As you can see, its doing running value horizontally.
I want it to do it vertically by each code like below:
MAYBE USING THE COLUMN GROUP AS SCOPE WILL WORK? I AM NOT SURE HOW TO USE COLUMN GROUPS IN SCOPE. ANY IDEAS?
You can try this by writing custom code -
Go to Report Properties and write code
public corder as integer
Function GetcOrder(order as integer) as integer
corder =corder + order
Return corder
End Function
Give a Name to Order text box
Next write an expression to calculate cumulative order value by calling function written in first step
preview output
Repeat the same step for rest of cumulative values .. please make sure to define public variable like
public corder as integer
All the Best!
Got it working!
Using the column group as scope works. I was using Nothing before as the scope. THen tried using the group in square brackets until i realised it needs to be passed as a string like "groupName"
Related
I am using the below code to add a Row # column in my report:
Dim row AS integer
Public Function GetRow() As Integer
row = row + 1
return row
End Function
When running the report, the report returns 29 rows and the row column seems to be working perfectly, labeling all rows 1–29 in the preview. However, when I export to PDF, the rows in the report change from 30–58. I have no idea what is causing the issue.
Is there something that the PDF is doing that handles the function differently? Does the PDF even use the function?
If not, then what can SSRS be doing that causes the function to rerun when exporting?
Why can't SSRS just export what I see on my screen?
If you want to just display the row number you can use SSRS function. just put this code in your tablix column in which you want to display row number.
=RunningValue(Fields!ProductId.Value, CountDistinct, "{name of dataset}")
I'm not sure why your function isn't working correctly, but there's an easier way. SSRS has a built-in RowNumber keyword. You should just be able to put the keyword in the table with the dataset you're using in parenthesis as a parameter of the function.
=RowNumber("yourDatasetHere")
You could also use =RowNumber(Nothing) to specify that the function should use the outermost dataset used in the table.
I've run into an issue where my alignment was off on PDF but was fine elsewhere. I had to put page breaks using =Ceiling(RowNumber(Nothing)/37).
That might not be what is causing your issue, but for me, when I forced a finite number of rows on each page, it fixed it for me. Sometimes I've had to group things, or do things that didn't make sense to fix it.
Trying to use the following expression in a matrix in my report:
=RunningValue(Fields!orderCount.Value,SUM,"RedemptionData")
But it gives the error:
The Value expression for the text box '' has a scope parameter that is not valid for RunningValue, RowNumber or Previous. The scoke parameter must be set to a string constant that is equal to the name of a containing group within the Tablix''.
Any ideas what I might be doing wrong?
Cheers
Im such an idiot. Just realised there is no scope on this. Used the following code which works perfectly fine:
=RunningValue(Fields!orderCount.Value,SUM,Nothing)
I am trying to create a footer that is using ProperCase within SSRS 2008
I have tried
=Code.ProperCase(LCase(Fields!aField1.Value, "DataSet1"))
to use the ProperCase field within the footer but it is stating that I do not have the text box linked to a DataSet.
Help would be much appreciated.
I don't think the problem lies with the ProperCase function. However, when inserting a value from a dataset, outside the context of the dataset, you must specify what record to use. For example, to use the first record from the dataset in your page footer, you should write your expression like this:
=Code.ProperCase(LCase(First(Fields!aField1.Value, "DataSet1")))
In other words, the reference to "DataSet1" makes no sense in the LCase-function, which is just a simple string manipulation function. To reference the dataset, you must use one of the Aggregate functions (in this case, First()), which takes as second argument the name of the dataset in question.
I assume you have written the ProperCase function yourself? There is a VBA function available in SSRS that allows you to change the case of a string and it's called StrConv which you could've used.
In your case you'd write: StrConv(First(Fields!aField1.Value, "DataSet1"), vbStrConv.ProperCase)
The other benefit of the StrConv function is that you can specify a localeID too if that is of any relevance.
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.
I have succeeded in building a number of group variables within an SSRS report, however what I want to do now is to use that variable outside of the group.
eg - I have a variable that calculates a payment within one dataset, and another one that calculates a payment within another dataset.
The first would be =Variables!QualityPayment.Value, the second would be =Variables!RevenuePayment.Value. Revenue and Quality are displayed in different SSRS tables.
I want to add the Quality Payment and Revenue Payment together, but when I try and put them outside of the table I get the error message
'Expressions can only refer to a Variable declared within the same grouping scope, a containing grouping scope, or those declared on the report.'
How do I go about adding the two together?
Thanks in advance
Jon
What I would do would be to use the group variable just as a way to add the values to an external variable, declared on the VB Code section of the report:
On the Report Properties -> Code section you use the following code:
Dim variable1 AS Integer
Function addValue(ByVal value AS Integer)
variable1 += value
End Function
Function getValue()
return variable1
End Function
Then on the group variable section of the tablix, you just call addValue(somefield) and when you need to access the calculated value you can do it from outside the group by calling the getValue function.
Assuming that both datasets are accessing the same database, I suggest combining the two datasets into a single dataset.
In your definition of the variables, make sure that any aggregate functions have the dataset specified for the scope, i.e.:
=SUM(Fields!MyFieldName.Value, "DataSet1") / 12