Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello Qlik folks,
Some one please explain what this below if condition means
if (COMPCOST_OPENPO_NOOH_Ind_In = 0 and alt(ITEM_CURRENT_MATL_COST_BOM_In,0) > 0, alt(ITEM_CURRENT_MATL_COST_BOM_In,0) * BOM_USAGE_In + alt(ITEM_CURRENT_MATL_OH_COST_BOM_In,0) * BOM_USAGE_In, COMPCOST_OPENPO_In) as COMPCOST_OPENPO_In2,
Thanks,
D
Your Expression - rewritten so that it will be easy to read
if (COMPCOST_OPENPO_NOOH_Ind_In = 0 and alt(ITEM_CURRENT_MATL_COST_BOM_In,0) > 0,
alt(ITEM_CURRENT_MATL_COST_BOM_In,0) * BOM_USAGE_In
+
alt(ITEM_CURRENT_MATL_OH_COST_BOM_In,0) * BOM_USAGE_In, COMPCOST_OPENPO_In
)
as COMPCOST_OPENPO_In2,
First of all Alt Function -
The Alt function is a conditional function and returns the first of the parameters that has a valid numeric Representation (Including dates). If no such match is found, it will return the last parameter (Last value in the list). Any number of parameters can be used.
alt(case1[ , case2 , case3 , ...] , else)
So in your case Any non numeric value Or null will be defaulted with '0' due to Alt function.
So - If COMPCOST_OPENPO_NOOH_Ind_In = 0 AND ITEM_CURRENT_MATL_COST_BOM_In > 0 - If both these conditions met
then -
SUM up
alt(ITEM_CURRENT_MATL_COST_BOM_In,0) * BOM_USAGE_In
AND
alt(ITEM_CURRENT_MATL_OH_COST_BOM_In,0) * BOM_USAGE_In
IF NOT
then -
COMPCOST_OPENPO_In
AS
COMPCOST_OPENPO_In2
Your Expression - rewritten so that it will be easy to read
if (COMPCOST_OPENPO_NOOH_Ind_In = 0 and alt(ITEM_CURRENT_MATL_COST_BOM_In,0) > 0,
alt(ITEM_CURRENT_MATL_COST_BOM_In,0) * BOM_USAGE_In
+
alt(ITEM_CURRENT_MATL_OH_COST_BOM_In,0) * BOM_USAGE_In, COMPCOST_OPENPO_In
)
as COMPCOST_OPENPO_In2,
First of all Alt Function -
The Alt function is a conditional function and returns the first of the parameters that has a valid numeric Representation (Including dates). If no such match is found, it will return the last parameter (Last value in the list). Any number of parameters can be used.
alt(case1[ , case2 , case3 , ...] , else)
So in your case Any non numeric value Or null will be defaulted with '0' due to Alt function.
So - If COMPCOST_OPENPO_NOOH_Ind_In = 0 AND ITEM_CURRENT_MATL_COST_BOM_In > 0 - If both these conditions met
then -
SUM up
alt(ITEM_CURRENT_MATL_COST_BOM_In,0) * BOM_USAGE_In
AND
alt(ITEM_CURRENT_MATL_OH_COST_BOM_In,0) * BOM_USAGE_In
IF NOT
then -
COMPCOST_OPENPO_In
AS
COMPCOST_OPENPO_In2
Is maybe easier to read if you break up the parts of the IF statement and indent (also indenting the + in the value if true as it keeps wrapping around on me);
if (COMPCOST_OPENPO_NOOH_Ind_In = 0 and alt(ITEM_CURRENT_MATL_COST_BOM_In,0) > 0,
alt(ITEM_CURRENT_MATL_COST_BOM_In,0) * BOM_USAGE_In
+ alt(ITEM_CURRENT_MATL_OH_COST_BOM_In,0) * BOM_USAGE_In,
COMPCOST_OPENPO_In
) as COMPCOST_OPENPO_In2,
alt function just takes the first numeric in the list supplied, so in this case is a shorter way of returning 0 when the fields are empty/null.
Cheers,
Chris.