Defined expression in SSRS report is displaying #ERROR - sql-server

I have defined an expression in one of my cells from my dataset1. My Design window and I have to repeat for each month's cells but I'm getting an #ERROR when I click on the PREVIEW tab in SSRS.
My thought is if the ActivityMonth value = 1 and the Type value = "PIF" then display the value in the Data column.
=IIF(Fields!Activity_Month.Value = 1 AND Fields!Type.Value = "PIF", Fields!Data.Value, 0)
I got this WARNING from SSRS:
[rsRuntimeErrorInExpression] The Value expression for the textrun ‘Textbox1471.Paragraphs[0].TextRuns[0]’ contains an error: Input string was not in a correct format.
But it ran successfully.

From the comments and the edit history, it looks like you have used & mark which is used to concatenate strings instead of AND keyword. After editing the expression - for me - the following expression looks great:
=IIF(Fields!Activity_Month.Value = 1 AND Fields!Type.Value = "PIF", Fields!Data.Value, 0)
But i have two remarks:
It may cause an error due to the different data types returned by the expression (0 is integer, Data.Value has another data type:
If Fields!Data.Value is of type string then use the following expression:
=IIF(Fields!Activity_Month.Value = 1 AND Fields!Type.Value = "PIF", Fields!Data.Value, "0")
Another thing to mention is that if value contains null it may throw an exception, so you have to check if field contains null:
SSRS expression replace NULL with another field value
isnull in SSRS expressions

Related

How to get value in loop by determine table field dynamically?

In SAP there is a table T552A. There are several fields like TPR, TTP, FTK, VAR, KNF as per day of a month such as TPR01, TPR02, etc.
In a loop I would like to access the said fields by determining the table field dynamically instead of hard coding of field name, like below:
DATA: ld_begda LIKE sy-datum,
ld_endda LIKE sy-datum.
DATA: lc_day(2) TYPE c.
DATA: lc_field(10) TYPE c.
DATA: lc_value TYPE i.
ld_begda = sy-datum.
ld_endda = ld_begda + 30.
WHILE ld_begda <= ld_endda.
lc_day = ld_begda+6(2).
CONCATENATE 't552a-tpr' lc_day INTO lc_field.
lc_value = &lc_field. " Need support at this point.
ld_begda = ld_begda + 1.
ENDWHILE.
Something like this (depending on the exact requirement):
FIELD-SYMBOLS: <lv_tpr> TYPE tprog.
DATA: ls_t552a TYPE t552a.
DATA: lv_field TYPE fieldname.
WHILE ld_begda <= ld_endda.
lv_field = |TPR| && ld_begda+6(2). "Dynamic field name
ASSIGN COMPONENT lv_field
OF STRUCTURE ls_t552a
TO <lv_tpr>.
IF sy-subrc EQ 0.
... "<lv_tpr> has now the value of the corresponding field
ENDIF.
ld_begda = ld_begda + 1.
ENDWHILE.
To store the result of a dynamic field a variable is needed that can store values of arbitrary types, in ABAP this is supported through field symbols.
A component of a structure (i.e. the row of the table) can then be assigned to a field symbol with ASSIGN COMPONENT:
ASSIGN COMPONENT lc_field OF STRUCTURE row_of_table TO FIELD-SYMBOL(<value>).
" work with <value> here
Recently new generic expressions were introduced (and now also support structures) which would allow you to write this (sooner or later):
... row_of_table-(lc_field) ...

ssis derived column - check if date field is null

In SSIS derived column I need to check if a Date field is empty or null, I'm using this expression but I got an error:
TRIM([date field]) == "" ? NULL(DT_DATE) : TRIM([date field])
The field is of DT_DATE data type. What's wrong in that?
I've used expressions like this successfully:
TRIM(String_field) == "" ? NULL(DT_WSTR,255) : TRIM(String_field)
You are combining data types (if true is a date and false is a string).
This is the correct formula:
TRIM([date field]) == "" ? NULL(DT_DATE) : (DT_DATE)TRIM([date field])
I am assuming [date field] is a string.
Concerning the error, it is related to the derived column result data type, since in conditional operators (?:) both true and false expression must generate the same data type.
In addition, your expression doesn't check for NULL values, you should use the following expression:
TRIM(REPLACENULL([date field],"")) == "" ? NULL(DT_DATE) : (DT_DATE)TRIM([date field])
Also, you have to make sure that [date field] can be parsed as date, so (DT_DATE)TRIM([date field]) will not throw an exception, you can use the error output to handles the value that doesn't contain a valid date.

Replace NULL in SSIS

I'm using 2 lookups in ssis for 2 tables. If a column is null in the other table, im going to use the other value and vice versa.
how to implement this one?
Here is one idea how to do it:
Lookup component:
Add the column of the other table as a new column (like 'column2').
After the lookup put a derived column:
Derived column name will be your initial column, set it to replace the original column.
In the expression put:
REPLACENULL(column,column2)
Use your look up component, and add the new column (Correspondant value in Lookup Table)
Assuming that your columns names are LookupColumn1 and LookupColumn2 And OutColumn is the expected output column:
First Method
Add a script component
Mark LookupColumn1 and LookupColumn2 as Input
Add an Output Column OutColumn ( DataType: DT_STR or DT_WSTR)
In your Script Write the following Code (inside ProcessInputRow Sub) :
Public Overrides Sub InputBuffer0_ProcessInputRow(ByVal Row As InputBuffer0)
If Not Row.LookUpColumn2_IsNull AndAlso _
Not String.IsnullOrEmpty(Row.LookUpColumn2.Trim) Then
Row.OutColumn = Row.LookUpColumn2.Trim
ElseIf Not Row.LookupColumn1_IsNull AndAlso _
Not String.IsnullOrEmpty(Row.LookupColumn1.Trim) Then
Row.OutColumn = Row.LookupColumn1.Trim
Else
Row.OutColumn_IsNull = True
End If
End Sub
Script Logic: If LookupColumn2 is not null or empty, it's value is assigned to OutColumn , if LookupColumn2 is null or empty we checks the value of LookupColumn1 : if it is not null or empty, it's value is assigned to OutColumn , else OutColumn is NULL
Second Method
Create a derrived column with the following expression
REPLACENULL(LookupColumn2,LookupColumn1)
Read more about REPLACENULL In this MSDN article

Updating an array and converting from varchar to integer

I'm updating an array by adding a varchar to an int4 array. The 'varchar' field is all numbers so I tried casting it to ::integer but it isn't working
update dwh.attr_lookup set kli_tree = array[target_909_kli::integer] || kli_tree
is giving me this error
ERROR: ERROR: invalid input syntax for integer: ""
Query = update
dwh.attr_lookup set kli_tree = array[target_909_kli::integer]
|| kli_tree
What is the proper way to do this?
You're trying to cast an empty string to an integer and that doesn't work:
=> select ''::int;
ERROR: invalid input syntax for integer: ""
LINE 1: select ''::int;
^
You'll have to decide what you want to do with empty strings. If you want to convert them to zeros, then something like this should work:
array[case when target_909_kli = '' then 0 else target_909_kli::integer end]
Obviously your varchar field is not all numbers. There would not be any double quotes in this case - as the error message informs us.
Try giving a full example if the error has not clear by now. Including table definition and sample values.

Range parameter on the MDX-query

I have a correct MDX-query:
SELECT NON EMPTY { [Measures].[IssueOpened] } ON COLUMNS,
NON EMPTY { ([Projects].[Id].[Id].ALLMEMBERS * [Priorities].[Id].[Id].ALLMEMBERS ) } ON ROWS
FROM [Reports]
WHERE [CreatedOn].[Date].&[2010-01-01T00:00:00]:[CreatedOn].[Date].&[2010-02-01T00:00:00]
I need to create SSRS-report with filter on CreatedOn dimension.
Here is my non-working solution:
I transform query to:
SELECT NON EMPTY { [Measures].[IssueOpened] } ON COLUMNS,
NON EMPTY { ([Projects].[Id].[Id].ALLMEMBERS * [Priorities].[Id].[Id].ALLMEMBERS ) } ON ROWS
FROM (SELECT (STRTOSET(#CreatedOnDate, CONSTRAINED) ) ON COLUMNS
FROM [Reports])
CreatedOnDate parameter (type = datetime)
Set value of CreatedOnDate parameter to value:
="[CreatedOn].[Date].[" + Format(CDate(Parameters!CreatedOnDate.Value), "yyyy-MM-dd") + "T00:00:00]"
But when I run the report I get:
The restriction imposed by the CONSTRAINED flag in the STRTOSET function were violated
Somehow the parameter is not what you think. CONSTRAINED flag will force generating an error if the string is not a member when using StrToSet MDX function (check the failing example) :
You can try without the CONSTRAINED flag or find out the value of your parameter :
WITH
MEMBER myParam AS "[CreatedOn].[Date].[" +
Format(CDate(Parameters!CreatedOnDate.Value), "yyyy-MM-dd")
+ "T00:00:00]"
SELECT
[Measures].[myParam] on 0
FORM [Reports]
Playing a bit with this should make easier spotting the issue.
It should work if you use STRTOMEMBER for each side of the range
STRTOMEMBER("[CreatedOn].[Date].&[2010-01-01T00:00:00]", constrained):STRTOMEMBER("[CreatedOn].[Date].&[2010-02-01T00:00:00]", constrained)

Resources