In SAP HANA you can create a calculated column. One example of a calculated column is converting string to integer.
Unfortunately in the source column are not always numbers (we expected only numbers)
So is there a way to do exception Handing for calculated columns (or any other kind of a default value in case of failure?
Workaround:
Check if the cell is numeric. And use a fall-back value if the cell is not numeric:
case
when length(ltrim(WERT_TEXT,' +-.0123456789')) > 0 then 0
else trim("WERT_TEXT")
end
Related
Is is possible in a Table to Calculate differences between Dates if the Value in the field is considered "short text"?
I am working to convert an Excel macro database into Access one and I have imported the data from the Excel file into an Access Table.
however i realized 2 feilds that count up until closure are now just fixed numbers but need to add up as each day passes until closure
when i imported the Dates became Short Text.
is there an expression that would handle this situation?
Each record has a serialized non repeating ID number seperate from access as well.
Dates I have are
OfficialissuanceDate,
DatePlanSubmitted,
DatePlanCompletedSubmitted,
DateClosed,
I need 2 calculations that increments daily when DateplanSubmitted and DatePlanCompletedSubmitted are null
Both comparing to OfficialIssuanceDate. then stop counting when they are no longer null. (have a date in updated to the record) and retain the value.
I have tried to Google calculating Dates but i get DateDiff function which doesnt appear to work. I've used Access and taken a class on it but never really made a new DB from scratch
Dates in a text field are not actual dates, just strings of characters. A Date/Time field stores value as a double number then displays in a date structure - "dd/mm/yyyy" is Access default structure.
Sometimes Access will do implicit conversion of data but not in this case. Either change field type to Date/Time or do conversion with CDate() function. However, you will find that conversion functions error with Null input.
Arithmetic operation with Date/Time field type is possible. However, arithmetic when any term is null returns Null so have to deal with that. One way uses Nz() function: Nz([DateClosed], Date()) - [DateOpened]. Unfortunately, Nz() is not available in table Calculated field type, so do that calc in query or textbox. Most developers avoid table Calculated field type. If you really want to use, expression would have to be: IIf(IsNull([DateClosed), Date(), [DateClosed]) - [DateOpened].
I currently have this formula in my report
=(Sum([Final]*[Units]))/Sum([Units]))
Final - Mostly Integer but has the NG mixed in the records
Units - Integer
Re-Exam - Contains Integer
Now, with my current formula, if [Final] encounters the value NG, the report gives an error, I want to determine the if the value of [Final] is NG, [Re-Exam] will be checked if it contains a value else 0 will be added to the Sum[Final] and if [Re-Exam] contains a value, [Re-Exam]*[Units] will be added to Sum[Final]
the final result displays the result in general number format
I am thinking of using IIF but can't generate the correct formula at the moment and that's what i need to fix
Try using Val which returns 0 for a non-numeric string.:
=Sum(IIf(Val([Final])=0,Val([Re-Exam]),Val([Final]))*[Units])/Sum([Units])
I have a column ProjectYear and a column ProjectNumber; both are numbers. I created a calculated column ([ProjectYear] & "" & [ProjectNumber]) which concatenates the two. For instance, 2015 and 123 gives 2015123.
The issue is that the resulting type of that calculated columns is Short Text, and when I create a query to join to another table which has that column in, but as a numeric type, I get a type mismatch error.
How can I make the calculated column have a numeric type?
I tried CInt([ProjectYear] & "" & [ProjectNumber]), but that it is not allowed.
A calculated field expression can only use a limited set of functions. CInt() is not supported, but Int() is.
I tested this one in Access 2010, with Long Integer for the calculated field's Result Type property, and it does what I think you want ...
Int([ProjectYear] & [ProjectNumber])
Note I believe you are asking about a calculated field in table design, such as this ...
Also note that a calculated field can not be indexed. That has performance implications when you use that field in a join to another table --- although the datatypes can be compatible, it can't take advantage of indexed retrieval.
Currently I am working on a ssrs report. The table in report is having about 30 columns. For each column I have to modify the number format (to either 2 decimal or no decimal numbers). I can do it by click on every column and modify the number property in format menu. But is there any way to format all the columns at a time?
I tried to select entire row -> F4 -> properties -> Number -> Format-> Expression. And set expression to:
=FormatNumber(Fields!HoursWorked.Value&Fields!ContactAttempted.Value&Fields!UnableToContact.Value,2)
But it throws an error
Type character '&' does not match declared data type 'Object'.
Can any one help me on this?
This is really, really stupid; you have to have spaces before and after the ampersand, and if you don't then you tend to get that error message. I don't know why, it's daft as hell but I bet that's it. Catches me out constantly. Try:
=FormatNumber(Fields!HoursWorked.Value & Fields!ContactAttempted.Value & Fields!UnableToContact.Value,2)
If you want to set the Format property of a cell (or cells - note you CAN set the format for multiple cells at the same time) then you need to specify a value or expression that resolves to a recognised format string, e.g. '$'0,.00;'$'-0,.00 or C2.
The expression you have given returns the actual formatted value of the cell, so this will not work if entered into the Format property - this needs to go in the Value property of the textbox.
You need to set format number for each column separately. If you don't want to set number format in Text Box Properties, you can set format such way:
Click on cell with value -> F4 -> field Format in Properties -> set format (for example, you can use this format: #,0.00 for numbers with space as 1000 separator and negative numbers as -12 345.00)
The matrix's odd rows contain strings, representing integer numbers. The even rows contain strings, representing dates in mm/dd/yyyy format. The order is not guaranteed, it could be the other way around if someone changed the category names.
The grand total row has to be added to this matrix, but the following expressions throw an #Error:
=Sum(Iif(IsDate(Fields!Data.Value), 0, CInt(Fields!Data.Value)))
=Sum(Iif(InStr(Fields!Data.Value, "/"), 0, CInt(Fields!Data.Value)))
Converting 0 and field value to some other numeric data types did not work too.
Interesting enough, the expressions partially work for the grand total column, i.e. they calculate the numbers' row total, but #Error on the dates rows.
Protecting the row grand total as follows did not help either:
=Iif(Fields!Results.Value = "# of items", CStr(Sum(CInt(Fields!Data.Value))), "")
What is the correct way to implement data driven conditional totals?
I could do this in plain SQL and dump into a tablix in a heartbeat but this has to be wrapped in SSRS and used with an existing matrix which must not be changed otherwise.
The #ERROR you get on the date rows is due to the CInt conversion failing.
This is because IIF is a function, not a language construct so both the true and false parameters get evaluated before being passed to the function regardless of the value of the boolean condition parameter. This means that:
=Sum(Iif(IsDate(Fields!Data.Value), 0, CInt(Fields!Data.Value)))
will always attempt the conversion to integer regardless of the result of the IsDate function.
Try using Val instead of CInt. The problem with CInt is it errors when the string to be converted is an inappropriate form; Val doesn't have that problem - it simply grabs whatever numbers it can. So you can use the expression:
=Sum(Iif(IsDate(Fields!Data.Value), 0, Val(Fields!Data.Value)))
and then simply format it like an integer.
Note that the Val function is still being run even when the field is not numeric but this expression succeeds because the Val function doesn't raise errors like Cint. We simply make the calculation and discard the result when the field is a date.
This expression, combining the tips from both answers with additional protection, works:
=Iif(
IsNumeric(Fields!Data.Value),
Sum(Val(Iif(InStr(Fields!Data.Value, "/"), "", Fields!Data.Value))),
0
)