I am making an SSRS report using SQL Server Report Builder. I have column and row grouping as follows :
I want to pick up the row that is highlighted in the red box below. How do I access that specific cell and display its value in some other table in the report? As you can see the value that I want to access is a column grouping total.
Use custom code:
Function SumLookup(ByVal items As Object()) As Decimal
If items Is Nothing Then
Return Nothing
End If
Dim suma As Decimal = New Decimal()
Dim ct as Integer = New Integer()
suma = 0
For Each item As Object In items
suma += Convert.ToDecimal(item)
Next
return suma
End Function
Then in the cell where you want to reference the value:
=Code.Sumlookup(lookupset("2073/074",Fields!FiscalYear.Value,Fields!Value.Value,"DataSet"))
*
lookup("2073/074",Fields!FiscalYear.Value,Fields!Alfa.Value,"DataSet"))
As the cell you want does not have a specific design time name, you won't be able to reference it directly. You'll have to recalculate the value in your second table. You'll have to determine the criteria but assuming it always the last fiscal year and Particular = fixed percentage... then...
You should be able to do it with something like (untested)...
=SUM(IIF(Fields!FiscalYear.Value = Last(Fields!FiscalYear.Value) AND Fields!.Particular.Value = "Fixed Percentage of Gross Income [c=(axb)]", Fields!Value.Value,0))
Related
For each group in SSRS (Countries, cities...) I calculate sales divided by exchange rates:
Sum(Fields!Net_Sales_Amount.Value)/LOOKUP(Fields!Country.Value, Fields!Country.Value, Fields!RATE.Value, "Currency")
How I can create Total of this sum (sum for last group - countries)?
Each solution that I found show how to do it only for alone LOOKUP function. I need to divide field by it.
Here is layout of my report:
and structure:
To calculate sales for country I just need to sum sales and divide it by LOOKUP function, but I couldn't do it for Total. I need to some below values.
I think you just need to change which data you are summing together, as it looks like you are simply finding exchange rates?
If this is the case, you should be able to just use
=Sum(Fields!Net_Sales_Amount.Value/LOOKUP(Fields!Country.Value, Fields!Country.Value, Fields!RATE.Value, "Currency"))
in your total textbox, which needs to be outside the group you are using to show the individual values.
If you want to lookup a lot of values and then sum them all together however, this is a little more complex.
Rather than using lookup, you will need to use lookupset, which uses the same syntax but can return more than one value. There is, however, no built in function that can sum these returned values up, as the values that get returned in the lookupset function are actually objects rather than numbers. As such, you will need to use custom code.
Open up your Report Properties and then the Custom Code window, into which you can paste the following:
Function SumLookup(ByVal items As Object()) As Decimal
If items Is Nothing Then
Return Nothing
End If
Dim suma As Decimal = New Decimal()
Dim ct as Integer = New Integer()
suma = 0
ct = 0
For Each item As Object In items
suma += Convert.ToDecimal(item)
ct += 1
Next
If (ct = 0) Then return 0 else return suma
End Function
This can then be used in a textbox as an expression:
=Code.SumLookup(LookupSet(Fields!Country.Value, Fields!Country.Value, Fields!RATE.Value, "Currency"))
which you can use alongside other numeric values for aggregations or calculations.
I am having trouble showing/hiding a column based on parameter value chosen.
How my report is set up:
Parameter: ImportStatus --ImportStatus parameter has three values you can choose from: M, V, E
If I choose ImportStatus value = 'M', then I want the report to display a specific column.
Currently, if I go to Column Visibility screen of a column I want to show/hide, I am able to hide column for all values instead of specific. Any idea how to do this correctly?
My expression:
=IIF(Parameters!ImportStatus.Value = "M",true,false)
The expression
=IIF(Parameters!ImportStatus.Value = "M",true,false)
will give the same result as
=(Parameters!ImportStatus.Value = "M")
The expression you need to give specifies whether or not to hide the column, so to show a column where #ImportStatus = "M", you would simply reverse the logic:
=Not(Parameters!ImportStatus.Value = "M")
I'm having some trouble trying to make a function that acts like vlookup but returns a range rather than a cell
The data to search through looks like this
Sometimes there is a space separating sometimes not
What I would like to do is to look up 16 from my main page and return all the values in that range.
the code I currently am using will only return the first line in a messagebox
Public Function findrulepos(target) As Range
Dim ruleStart, ruleEnd, ruleEnd2 As String
Dim RuleRange As Range
'Dim ruleEnd As Range
MaxRule = 100000
MaxRow = 100000
Set target = Sheets("main").Range("E2")
Sheets("ResRules").Select
For i = 3 To MaxRow
If CStr(ThisWorkbook.Sheets("ResRules").Range("A" & i).Value) = _
CStr(target.Value) Then
ruleStart = _
ThisWorkbook.Sheets("ResRules").Range("A" & i).Offset(0, 1).Text
Exit For
Else
End If
Next i
End Function
If we can assume that the numeric group labels in col A are sequential, then I think this will achieve what you need:
Enter the numeric label you are wanting to extract (16 in your example) into cell E1
Note that =MATCH(E1,A:A,0) gives us the row number where group 16
starts, which is the first row we want to copy. Similarly,
=MATCH(E1+1,A:A,0) gives us the row number where group 17 starts,
which is one row below the last row we want to copy. (Unfortunately
that's not true for the very last group of code, but to rectify that
you just need to add a dummy number at the very bottom of the data
in col A.)
Enter the formula =IF(ROW()+MATCH(E$1,A:A,0)-1<MATCH(E$1+1,A:A,0),INDIRECT("B"&MATCH(E$1,A:A,0)+ROW()-1),"") in F1. That should copy the first value of the selected code block -- [DO] ADD TO QUEUE P in your example.
Copy F1 down as many rows as the largest code block is likely to be.
The one problem with that is that it will put 0 whenever it copies a blank row. So you have to explicitly check for that case, e.g. by changing the formula in F1 to =IF(ROW()+MATCH(E$1,A:A,0)-1<MATCH(E$1+1,A:A,0),IF(ISBLANK(INDIRECT("B"&MATCH(E$1,A:A,0)+ROW()-1)),"",INDIRECT("B"&MATCH(E$1,A:A,0)+ROW()-1)),"")
I have an RDL file where I enter two dates, run a query based on that date range to populate a drop-down list and then populate another text field with a default value that is based on the Label of the drop-down list's selected item.
The Data Types are Date/Time for the first two dates, Text for the drop-down list and Text for the last text field. The drop-down list's Value as returned by the query is actually a Date/Time but if I set the Data Type to Date/Time then it does not work as expected when I Preview the report (when I select a value in the list the current selection just reverts back to "<Select a Value>" and nothing is put into the last Text field, regardless of its Data Type).
Anyway, with the drop-down list having a Data Type of Text, all works OK in the Preview.
The problem is that I have custom interface for the reports, and try as I might, I cannot get my own implementation to correctly get the default value for my last Text field.
I noticed that SSRS only wants dates in a certain format and so with some manipulation of the dates I can get the ValidValues for the drop-down list parameter by calling GetReportParameters() with the Values parameter set as follows:
values[0].Name = "fromdate";
values[0].Value = "2011-11-01 00:00:00";
values[0].Label = "";
values[1].Name = "todate";
values[1].Value = "2011-11-30 00:00:00";
values[1].Label = "";
parameters = GetReportParameters("myreport", null, true, values, null);
Following this call, parameters[2] now contains ValidValues and I can populate my own drop-down list in the custom UI.
However, when I need to get the default value for the text field, I cannot seem to get the input values in a format that GetReportParameters() will accept:
values[0].Name = "fromdate";
values[0].Value = "2011-11-01 00:00:00";
values[0].Label = "";
values[1].Name = "todate";
values[1].Value = "2011-11-30 00:00:00";
values[1].Label = "";
values[2].Name = "datelist";
values[2].Label = "The date is 22nd Nov 2011";
values[2].Value = "2011-11-22 00:00:00";
parameters = GetReportParameters("myreport", null, true, values, null);
After this call I expect the parameter for my text field to have a DefaultValues value that I can access but it is 'null' the State is set to HasOutstandingDependencies. Why is this? All of the dependencies have been set - correctly as far as I can see, so what might be the issue?
I realise that I may be getting into difficulties with the conversion of Data Type between Date/Time and Text, but if I try to keep it consistent and use Date/Time throughout then I cannot get it to work even in the RDL's Preview, so I'm not sure that's the way to go either!
Thanks in advance.
I'm trying to add new output column using synchronous custom data flow component(below is the code). While testing I found that input columns I added are not getting displayed in Output columns only the new added column is getting displayed. I'm not sure where problem is. Please help!
Public Overloads Overrides Sub ProvideComponentProperties()
Dim input As IDTSInput100 = ComponentMetaData.InputCollection.New()
input.Name = "Input"
Dim Output As IDTSOutput100 = ComponentMetaData.OutputCollection.New()
Output.Name = "Output Rows"
Output.Description = "Output rows with unique row ID appended."
'Adds new column RowID to output columns list
Dim rowIDColumn As IDTSOutputColumn100 = Output.OutputColumnCollection.[New]
rowIDColumn.Name = "Row ID"
rowIDColumn.SetDataTypeProperties(DataType.DT_UI8, 0, 0, 0, 0)
Output.SynchronousInputID = input.ID
Thanks in advance
Sai
my bad! for Data flow components only new columns will be displayed in the advance editor, but when we take the output arrow and attach to destination(like excel or file or db) then it shows all the columns including the input columns and newly added columns in the mapping tab of destination editor. :)