I have Excel sheets where the same column can contain a value with % formatting and also with decimal notation.
To clarify: In Excel both have the same formatting but due to different Excel versions (locations) SSIS shows them like this:
1,3% or 0.814260540128523
These values come in as strings so I'm trying to figure out a way to divide the % formatted values by 100 and leave the others as is.
Initially I used:
(DT_R8)[F5_CONV] < 1 ? (DT_R8)[F5_CONV] : (DT_R8)[F5_CONV] / 100
in a second derived column but I then realized that 0,23% is also a possible value.
I think something like this should do it but I'm having trouble with the DT_WSTR and DT_R8 types.
(F5 == "" || ISNULL(F5)) ? NULL(DT_WSTR,40) : FINDSTRING(F5,"%",1) > 0
? (DT_WSTR,40)REPLACE(REPLACE(F5,".",","),"%","") / 100
: (DT_WSTR,40)REPLACE(F5,".",",")
Hope you can help me out here.
Thank you.
(F5 == "" || ISNULL(F5)) ? NULL(DT_WSTR,40) : FINDSTRING(F5,"%",1) > 0
? (DT_WSTR,40)((DT_R8)REPLACE(REPLACE(F5,".",","),"%","") / 100)
: (DT_WSTR,40)REPLACE(F5,".",",")
You can also use script component. Here is a quick solution; you may need to add validations for null. Let us know, if you need help.
Related
Hello I have a list with temperature values:
temperatures=[-2,1,10.2,6,15,-6,20,13.5,0.9,-8.3]
and I want to create 2 list containing 1 the values above zero and the other the values below. It is an exercise and I have to use for loop and conditional statment.
I created two additional empty values and I try to use the conditional statment to select the two ranges of values to complete the task, but Iàm not reaching the objective. Could you help?
this is the code I tried:
```
temperatures=[-2,1,10.2,6,15,-6,20,13.5,0.9,-8.3]
temp_below_zero=[]
temp_above_zero=[]
for i in range(len(temperatures):
if i < 0 :
temp_below_zero.append(i)
elif i > 0 :
temp_above_zero.append(i)
print(temp_below_zero,temp_above_zero)
```
`
```
You enumerated the value 'i', but didn't use it as an indexer for the list. You could either do this, or just iterate over each element in the list by itself:
temperatures=[-2,1,10.2,6,15,-6,20,13.5,0.9,-8.3]
temp_below_zero=[]
temp_above_zero=[]
for i in temperatures:
if i < 0 :
temp_below_zero.append(i)
elif i > 0 :
temp_above_zero.append(i)
print(temp_below_zero,temp_above_zero)
or using indexing (which I think you initially wanted to do):
temperatures=[-2,1,10.2,6,15,-6,20,13.5,0.9,-8.3]
temp_below_zero=[]
temp_above_zero=[]
for i in range(len(temperatures)):
if temperatures[i] < 0 :
temp_below_zero.append(temperatures[i])
elif temperatures[i] > 0 :
temp_above_zero.append(temperatures[i])
print(temp_below_zero,temp_above_zero)
This approach is very close and you are definitely on the right track. Take a look at your for loop.
for i in range(len(temperatures):
The loop, in this case, will run from values 0 to 10 (not including 10) stored as i. If instead, you want i to store each of the values in the list, rewrite your loop like this:
for i in temperatures:
This modification makes it so that i contains a value in the list through each iteration, instead of the indices of the list. I hope this is helpful!
How to convert this SQL query to an Excel formula?
CASE
WHEN UPPER(V_out) = 'GOOGLE' OR (UPPER(V_out) = 'APPLE' AND dis > 800)
THEN 2
ELSE
CASE
WHEN UPPER(V_out) IN ('APPLE', 'MOZILLA', 'SAMSUNG') OR UPPER(V_out) IS NULL
THEN 0
ELSE -2
END
END
So far I have tried this:
=IF(AND(CU2>800;OR(UPPER(LS2)="GOOGLE";UPPER(LS2)="APPLE"));2;IF(OR(MATCH(UPPER(LS2);{"APPLE";"MOZILLA";"SAMSUNG"};0);UPPER(LS2)=0);0)-2)
And it doesn't seem to work.
Any ideas where I made a mistake?
Thanks!
The MATCH needs a ISNUMBER(...) wrapper:
ISNUMBER(MATCH(UPPER(LS2);{"APPLE";"MOZILLA";"SAMSUNG"};0))
That way it returns a TRUE/FALSE and not a number or error.
and UPPER(LS2)=0 just needs to be LS2=""
and AND(CU2>800;OR(UPPER(LS2)="GOOGLE";UPPER(LS2)="APPLE")) does not quite match the case statement:
OR(UPPER(LS2)="GOOGLE";AND(UPPER(LS2)="APPLE";CU2>800))
is more like the case statement.
The -2 is in the wrong place.
=IF(OR(UPPER(LS2)="GOOGLE";AND(UPPER(LS2)="APPLE";CU2>800));2;IF(OR(ISNUMBER(MATCH(UPPER(LS2);{"APPLE";"MOZILLA";"SAMSUNG"};0));LS2="");0;-2))
I'm writing a macro to cycle through a number of different spreadsheets that are in exactly the same format as each other. The source spreadsheets contain data in a table which occasionally contains the #NUM error (thanks to something going wrong in a different model!)
I have managed to account for all other error types, and some interesting formatting rules, using the below with a few other Case statements:
If IsNumeric(resultsarray(q,p) = false then
Select case ResultsArray(q,p)
Case IsError(ResultsArray(q, p))
ResultsArray(q, p) = 0
Case Left(ResultsArray(q, p), 2) = "0 "
ResultsArray(q, p) = 0
Unfortunately #NUM doesn't seem to fall into IsError's purview. Does anyone out there know how I can simply overwrite the error with a zero/0?
Thanks in advance!!
Steph
This #NUM error occurs if the input is not a valid number. On your situation i suggets you to check whether the input is number or not instead of error check. This way you can check #NUM error as well.(Or you can do it both) With IsNumeric(<input data here>) you can do it. So just add one more case (IsNumeric) to your select case.
I have to test a condition where the parameters can be more than one string. For eg: I would like to test
if (cell1="CA" or cell1="OR" or cell1="NV" or .....)`
print 1
else
print 0
How do I do this? Excel only allows me to check maximum of 2 values in an or statement like this -
=IF((OR(U11="CT",U11="ME")),1,0)
Can someone help me how to do it?
Thanks.
The Excel OR function is not restricted to two conditions.
=IF(OR(U11="CT", U11="ME", U11="XX"), 1, 0)
More succinctly as,
=--OR(U11={"CT", "ME", "XX"})
I have 2 year-month prompts. If I don't select any year-month in 1st prompt, report should by default, run from January of the same year, selected in 2nd prompt. My prompts are value prompts and have string values. Please help me materialise the requirement. I have already tried # prompt macro, ?prompt?, case when etc. I am nto sure, If javascript would help.
I'm going to assume your underlying date fields are not stored as DATE value types since you're using strings. This may be easier split into 4 prompts: from month, from year, to month, to year.
The filter would then be an implied if:
(
(?FROM_YEAR? = '' or ?FROM_MONTH? = '') and
[database_from_month] = '01' and
[database_from_year] = ?TO_YEAR? and
[database_to_month] = ?TO_MONTH? and
[database_to_year] = ?TO_YEAR?
)
OR
(
(?FROM_YEAR? <> '' or ?FROM_MONTH? <> '') and
[database_from_month] = ?FROM_MONTH? and
[database_from_year] = ?FROM_YEAR? and
[database_to_month] = ?TO_MONTH? and
[database_to_year] = ?TO_YEAR?
)
The above style filter is superior for many reasons:
More likely to be sargeable
Easy to understand
Uses simple built-in Cognos functions; more likely to be cross-version compliant
No issues with cross-browser support you would get with Javascript
Code snippet would work in other Cognos studios (Business Insight, etc)
You've likely seen CASE statements in filters throws an error. The CASE statement is passed to SQL, not compiled into a SQL statement via Cognos. Hence it's not seen as proper syntax.