If Then Else in Infopath (Xpath): how to ? - sharepoint

I've a module in InfoPath / Sharepoint, a query field, and some fields.
I want to perform in formula a simple :
If (Condition) then
True Condition
Else
False Condition
In particular I want to write this formula:
If (FieldA = "") then
Get FieldB
else
Get FieldA
How to do in InfoPath formula ?
Thanks

If you want to use this as a default value, you can simply use the conditional default values. Therefor just use the following snippet:
(TrueResult | ElseResult) [(BoolCondition) + 1]
And in your case:
(FieldA | FieldB) [(string-length(FieldA) > 0) + 1]
For more information on this see:
https://blogs.msdn.microsoft.com/infopath/2006/11/27/conditional-default-values/

Related

SQL query to Excel formula conversion

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))

How to make custom references in an Excel row with specific rules ? with VBA or Excel formula

I Want to customise automatically in Excel a Reference number according to the content of the line it is representing.
I have a table for test procedure that looks like this :
Ref
Action
Check
A 001
Name of the Action to perform
Empty if it is an Action
C 001
Empty if it is a Check
Name of the Check to perform
C 002
Empty if it is a Check
Name of the Check to perform
C 003
Empty if it is a Check
Name of the Check to perform
A 002
Name of the Action to perform
Empty if it is an Action
The logic would be the following:
To iterate separately references starting with A and the ones starting with C depending on the type of procedure, that is to say whether the name of the procedure is in Action Column or Check Column.
I would like to implement an algorithm like this, or a formula that does the same thing :
For line in TABLE1 :
if ( TABLE1[line,Action] =! NULL && TABLE1[line,Check] = 0) :
Ref_Action = Ref_Action + 1
Ref_Code = "A" + Ref_Action
elif ( TABLE1[line,Action] =! NULL && TABLE1[line,Check] = 0) :
Ref_Check = Ref_Check + 1
Ref_Code = "C"+ Ref_Check
else raise error : "a procedure shall be either an action or a Procedure"
TABLE1[line,Ref] = Ref_Code
(It is not a code language, just my way of representing the algorithm, I hope it is readable.)
Unfortunately, I have no experience in VBA and I couldn't find a way to write an appropriate formula. Or maybe there is another way ?
Thank you,
Gautier

Cognos Report Studio: CASE and IF Statements

I'm very new in using Cognos report studio and trying to filter some of the values and replace them into others.
I currently have values that are coming out as blanks and want to replace them as string "Property Claims"
what i'm trying to use in my main query is
CASE WHEN [Portfolio] is null
then 'Property Claims'
ELSE [Portfolio]
which is giving me an error. Also have a different filter i want to put in to replace windscreen flags to a string value rather than a number. For example if the flag is 1 i want to place it as 'Windscreen Claims'.
if [Claim Windscreen Flag] = 1
then ('Windscreen')
Else [Claim Windscreen Flag]
None of this works with the same error....can someone give me a hand?
Your first CASE statement is missing the END. The error message should be pretty clear. But there is a simpler way to do that:
coalesce([Portfolio], 'Property Claims')
The second problem is similar: Your IF...THEN...ELSE statement is missing a bunch of parentheses. But after correcting that you may have problems with incompatible data types. You may need to cast the numbers to strings:
case
when [Claim Windscreen Flag] = 1 then ('Windscreen')
else cast([Claim Windscreen Flag], varchar(50))
end
In future, please include the error messages.
it might be syntax
IS NULL (instead of = null)
NULL is not blank. You might also want = ' '
case might need an else and END at the bottom
referring to a data type as something else can cause errors. For example a numeric like [Sales] = 'Jane Doe'
For example (assuming the result is a string and data item 2 is also a string),
case
when([data item 1] IS NULL)Then('X')
when([data item 1] = ' ')Then('X')
else([data item 2])
end
Also, if you want to show a data item as a different type, you can use CAST

How to nest more IF conditions in excel when first condition becomes FALSE?

The excel not accepting the formula
=IF(AND(Sheet1!BZ2<>"",Sheet1!CB2<>"",Sheet1!CD2<>"",Sheet1!CF2<>"",Sheet1!CH2<>"",Sheet1!CA2="",Sheet1!BC2="B"), IF(Sheet1!CA2="","",TODAY()-1),
IF(
IF(AND(Sheet1!BZ2<>"",Sheet1!CA2="",Sheet1!BC2="A"),IF(Sheet1!CA2="","",TODAY()-1),
IF(
IF(AND(OR(Sheet1!DB2="Completed - Knowledge Transfer"),AND(Sheet1!BC2<>"")),IF(Sheet1!CA2="","",TODAY()-1),
IF(Sheet1!CA2="","",Sheet1!CA2)
)
)
)
I am following the below syntax for IF .
=IF (logical_test, [value_if_true], [value_if_false])
I am trying to nest the other conditions whenever the statements gets FALSE
Please help.
Can someone pls find the syntax error I am doing in this
The If statement isn't nested properly and also you are using some AND Or statements which are again not used properly.
Simplifying your formula we get this
=IF(a,b,IF(IF(c,d,IF(IF(e,f,g)))
where ,
a = AND(Sheet1!BZ2<>"",Sheet1!CB2<>"",Sheet1!CD2<>"",Sheet1!CF2<>"",Sheet1!CH2<>"",Sheet1!CA2="",Sheet1!BC2="B")
b = IF(Sheet1!CA2="","",TODAY()-1)
c = AND(Sheet1!BZ2<>"",Sheet1!CA2="",Sheet1!BC2="A")
d = IF(Sheet1!CA2="","",TODAY()-1)
e = AND(OR(Sheet1!DB2="Completed - Knowledge Transfer"),AND(Sheet1!BC2<>""))This does not make sense
f = IF(Sheet1!CA2="","",TODAY()-1)
g = IF(Sheet1!CA2="","",Sheet1!CA2)
A proper nested IF will be of the form
=IF(a,b,IF(c,d,IF(e,f,g)))
Your formula can also be written as:
=IF(Sheet1!CA2="","",
IF(OR(
AND(Sheet1!BZ2<>"",Sheet1!CB2<>"",Sheet1!CD2<>"",Sheet1!CF2<>"",Sheet1!CH2<>"",Sheet1!BC2="B"),
AND(Sheet1!BZ2<>"",Sheet1!BC2="A"),
AND(Sheet1!DB2="Completed - Knowledge Transfer",Sheet1!BC2<>"")),
TODAY()-1,Sheet1!CA2))
The Syntax is a nested syntax (assuming a1 = 12 and b2=15:)
=IF(A1<13,IF(B1>13,"B1","Not Found"),"Not Found")
You overused IF() formula. I tried to simplify your formula, check this:
=IF(AND(Sheet1!BZ2<>"",Sheet1!CB2<>"",Sheet1!CD2<>"",Sheet1!CF2<>"",Sheet1!CH2<>"",Sheet1!CA2="",Sheet1!BC2="B"),IF(Sheet1!CA2="","",TODAY()-1),IF(AND(Sheet1!BZ2<>"",Sheet1!CA2="",Sheet1!BC2="A"),IF(Sheet1!CA2="","",TODAY()-1),IF(OR(Sheet1!DB2="Completed - Knowledge Transfer",Sheet1!BC2<>""),IF(Sheet1!CA2="","",TODAY()-1),IF(Sheet1!CA2="","",TODAY()-1))))
Nested view of formula above:
=IF(AND(Sheet1!BZ2<>"",Sheet1!CB2<>"",Sheet1!CD2<>"",Sheet1!CF2<>"",Sheet1!CH2<>"",Sheet1!CA2="",Sheet1!BC2="B"),
IF(Sheet1!CA2="","",TODAY()-1),IF(AND(Sheet1!BZ2<>"",Sheet1!CA2="",Sheet1!BC2="A"),
IF(Sheet1!CA2="","",TODAY()-1),
IF(OR(Sheet1!DB2="Completed - Knowledge Transfer",Sheet1!BC2<>""),
IF(Sheet1!CA2="","",TODAY()-1),
IF(Sheet1!CA2="","",TODAY()-1)
)
)
)

SSIS - if/else expression to turn string into number

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.

Resources