I am customizing an SSRS report, using an existing DataSource and DataSet. I can't edit the DataSet definition (no permissions and I'm not going to get it), so I have to work with the data provided. My problem is that some of the data is a bit garbled. I'm attempting to group columns on an "Iteration" text column, but it contains data like:
Iteration 01
...
Iteration 09
Iteration 1
Iteration 10
Iteration 11
....
Pending Scope
The "Iteration 1" field is in the middle and is really messing me up. How can I move this to the beginning of the set, or ideally merge it with Iteration 01? I can't do it in SQL, and it's not a trivial "number format", so I can't just apply a format to it.
How can group & display the data above with the numbers properly zero-padded on the left?
Many ways to do this, but which is best depends on the details of your incoming data. If the sample in the question is fairly complete then I would put some embedded code into the report:
Function ParsedTitle(Title As String) as String
Dim s as String
s = TRIM(Right(Title,2))
Dim num as Integer
If Len(Title) < 2 Then
return Title
End If
If Not Integer.TryParse(s, num) Then
return Title
End If
Return TRIM(LEFT(Title, Len(Title)-2) ) + " " + num.ToString("00")
End Function
(This was only lightly tested.)
Then set the expression in a field to be:
=Code.ParsedTitle(Fields!Title.Value)
Related
I am currently trying to work on fixing some cascading parameter issues I am having.
We recently put in a fix to a few SSRS reports that help with rerunning cascading parameters when the parent parameter is changed, if it helps, here is the instructions we followed to implement this: Cascading Parameters.
The main structure for most of our reports works like this:
#Hierarchy, select whether you want to filter by "Market" or "Region"
#HierarchySelection, select which markets or regions you want to filter by
#PropertyInternal, gets used to refresh #Property automatically each time #HierarchySelection is changed, this is populated by a SQL dataset
#Property, select which properties you want within those given markets or regions, the defaults are set up as Parameters.PropertyInternal.Value and get refreshed each time #HierarchySelection is changed
In order to get #Property to refresh properly, we have to feed #PropertyInterval with a NEWID() so it sees it as a new value each time it runs, so the value is CONCAT( Property, "|", NEWID() )...Property is always a 4 digit character
The issue I am having is that now is that subscriptions are failing because the Property parameter gets refreshed and unselects the values. Or if I have to feed it values, I can't exactly feed the NEWID() as I am unaware of what the value will be when the report is run.
My only thought is to try and remove the GUID from #PropertyInternal and feed that value to #Property instead, but either that is not possible or I just cannot figure out the syntax.
Any one have any better ideas for how I am handling this or if there is a way to remove the GUID?
I am essentially looking for something similar to this if possible, but getting the error below it.
=SPLIT(LEFT(JOIN(Parameters!PropertyInternal.Value,","), 4),",")
The report parameter 'Property' has expression-based ValidValues. The sizes of the value and the label (multi-value) arrays have to be identical. (rsInvalidValidValueList)
Public Function CommaSeparatedParam(ByVal strArray As Object()) As String
Dim returnStr As String = String.Empty
For Each str As String In strArray
returnStr = returnStr + Mid(str, 1, InStr(str, "|") - 1) + ","
Next
Return Left(returnStr, Len(returnStr) - 1)
End Function
Consider a table like the following
CREATE TABLE tbl1(
id INTEGER PRIMARY KEY,
someVal INTEGER
);
filled with some data (just to not feel like querying an empty table) and a query as follows
SELECT tbl1.ID, tbl1.someVal
FROM tbl1
WHERE (tbl1.ID In ([TempVar]![t1]));
The TempVars collection has been filled with the contents
TempVars.Add "t1", 1
TempVars.Add "t2", "2"
TempVars.Add "t3", "2,3"
via the immediate window.
Now when viewing the query results for different WHERE clauses the following scenarios work (meaning they display the expected results):
Querying for WHERE (tbl1.ID In ([TempVar]![t1])) returns the entry with id = 1
Querying for WHERE (tbl1.ID In ([TempVar]![t2])) returns the entry with id = 2
So far, everything as expected. But for WHERE (tbl1.ID In ([TempVar]![t3])) the query results are empty. Why?
(When I execute ?TempVars("t3") it returns 2,3 - when I then copy/paste that line into the query so it reads WHERE (tbl1.ID In (2,3)) it returns the entries 2 and 3...)
Things to consider:
I'm using the German version of Access 2013, which means that your name for the TempVars collection might differ (for me, in the VBE it's called TempVars, while the query design only allows access via [TempVar]).
Also when manually entering lists into the criterion field in query design mode, I need to separate them with a semicolon, whereas in SQL mode I'm required to use a comma. Stupid language differences. (Whether I define TempVars("t3") with a semicolon or comma doesn't change anything about the zero results, however...)
My research suggests that the very method presented above should work, so I assume I either implemented it wrong or there is something else at play.
My approach isn't necessarily tied to the usage of TempVars. When experimenting with the values of textbox and label controls on forms, I experienced the same issue.
The Why is very easy to answer. If TempVars("t3") contains a string "2, 3", it's only going to match entries where your ID is a string equal to "2, 3". You can't dynamically build IN criteria the way you're doing it, since the , can't be stored in a variable, it has to be present in the SQL.
To fix this, you can use a user-defined function to do the IN check for you. There aren't other solid workarounds as long as you're not dynamically changing your SQL.
Sample UDF:
Public Function SplitIn(commaseparatedlist As String, compare As Variant) As Boolean
Dim strInArr() As String
strInArr = Split(commaseparatedlist, ",")
Dim arrItem As Variant
For Each arrItem In strInArr
If arrItem = CStr(Nz(compare, "")) Then
SplitIn = True
Exit Function
End If
Next arrItem
SplitIn = False
End Function
Usage:
WHERE SplitIn([TempVar]![t3], tbl1.ID)
I am using the CopyFromRecordset command within Access to copy a series of tables into Excel. No worries with this process. My problem is making this routine be able to determine what format should be assigned to each sheet column of the workbook. I have extracted the Table's Field Object Type values and have compared these to the reference Microsoft Reference for the Field.Type property. ( http://msdn.microsoft.com/en-us/library/ms526865(v=EXCHG.10).aspx ). Unfortunately, what is returned does not accurately reflect the definitions in Access when compared to the MS stated values.
1) A date field returns a Type value of 8 corresponding to a vbString
2) A currency field returns a Type value of 5 corresponding to a vbDouble
3) A text field returns a Type value of 10 that is not even listed
4) A formated vbDouble returns a Type value of 7 coorisponding to a vbDate
The only return value that does seem to provide a valid reference if for an Integer Field with a Type value of 3
How do I get a valid table field format reference so that I can then format the corresponding worksheet columns correctly? I really don't want to have to create a reference table that will provide the desired format for each field in every table to be extracted. Fine as a work-around but certainly not very flexible as the table structure being extracted is dynamic via a series of CrossTab queries and not something I can easily use an Excel Template as I read as one solution.
Am I misunderstanding something here?
Thank you for the links and clarification to where I was headed off in the wrong direction with my efforts. The referenced link above by Ted led me to Allen Brown's function for returning the formating for the fields of a Table. As a result, I was able to accomplish my goal. Here is the specific code as reference.
'Write the Table Field Names to the Named Worksheet as Column Headers
'and format the columns for the Table.Field format
intRowCount = rst3.RecordCount
intColumnCount = rst3.Fields.Count
For i = 0 To intColumnCount - 1
xlSheet.Cells(1, i + 1).Value = rst3.Fields(i).Name
If i = 0 Then
.Sheets(strTable).Columns(i + 1).EntireColumn.AutoFit
End If
If i < 3 Then
.Sheets(strTable).Columns(i + 1).EntireColumn.HorizontalAlignment = xlCenter
End If
intFormat = CLng(rst3.Fields(i).Type)
.Sheets(strTable).Columns(i + 1).EntireColumn.Select
Select Case intFormat
Case 3
Selection.NumberFormat = "00"
Case 5
Selection.NumberFormat = "$#,##0.00"
Case 7
Selection.NumberFormat = "#,##0"
Case 8
Selection.NumberFormat = "yyyy-mm-dd"
Case 10
Selection.NumberFormat = "#"
End Select
Next i 'Next Column - Table Field to be copied
It may not be the most efficient as I am still developing ways to best use Excel objects from within Access.
If anyone has code improvements, I am certainly open to suggestions. Thanks again all.
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 =
i am showing jobid in my report. i want that if job ID are this 02,07.11,19,21,29,31,40 etc then those report rows will not be shown. i know how to hide rows writing expression but i just need to know if there any short cut way to say that my job is are 02,07.11,19,21,29,31,40.
still i am doing like =IIF(Fields!JID.Value = 02 or Fields!JID.Value = 07 or Fields!JID.Value = 11 or Fields!JID.Value = 19, True, False)
is there any way like =IIF(Fields!JID.Value in (02,07.11,19,21,29,31,40), True, False)
if i send job id as a parameter value send from calling environment like "02,07.11,19,21,29,31,40" then how to di it.
please let me inform.
Will it work for your purposes to handle this in SQL? You have a couple options...
Option 1
Set up a multi-valued, string parameter in your report called #JIDValues.
SQL sprocs do not accept arrays of values, so you will need to pass this as a string array to your sproc. In order to do this, you will need to join your values together in your report code that executes the stored procedure.
JOIN(Parameters!SiteGroupList.Value, ",") & "'"
Inside the sproc (or the report depending on your preference) you will need to append and prepend commas to your string so that the following will work for your values on the ends as well as in the middle of the string. The following WHERE clause will be able to determine if a specific Job ID is contained in the comma delimited string you passed to the sproc.
WHERE #JIDValues LIKE '%,' + LTRIM(RTRIM(STR(tableA.JID))) + ',%'
Option 2
Alternatively, if this is a static list, you could hard-code your sproc to exclude them.