Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
So I have a variable _Prefix.
I want to load a field only when the value for that variable is 'n1_co_'.
I tried the below, but get this error Field 'n1_co_' not found
IF($(_Prefix) = 'n1_co_', $(_Prefix)SenderSubId, '') as $(_Prefix)SenderSubId,
I tried the below, but the condition doesn't seem to apply (i.e. when the var is equal something else, it still tries to load $(_Prefix)SenderSubId)
IF('$(_Prefix)' = 'n1_co_', $(_Prefix)SenderSubId, '') as $(_Prefix)SenderSubId,
I tried the below, but it doesnt work, gives the error Field '_Prefix' not found
IF(_Prefix = 'n1_co_', $(_Prefix)SenderSubId, '') as $(_Prefix)SenderSubId,
Any ideas what I'm doing wrong?
Thanks
All specified fields within a load must exists within the source and this means within a load you couldn't check if a certain field exists or not and further if such things are necessary you will need additionally measures like using several specialized load-statements or doing the wanted transformation some load-steps later or using any pre-load to check which fields are there or similar measures.
- Marcus
Thanks for coming back Marcus. I may have oversimplified the issue. Below is the simplest version of the full loader
So I'm creating a function that builds tables with different names based on the arguments being passed. I want to make it so that when I call this function with a given _Prefix value, I only load the SenderSubId when i pass n1_co_ and not n2_ca_. hope that makes more sense
Sub CreateOrderTable(_TableName, _ResidentTable, _Prefix)
[$(_TableName)]:
LOAD
%$(_Prefix)id,
IF(_Prefix = 'n1_co_', $(_Prefix)SenderSubId, '') as $(_Prefix)SenderSubId
RESIDENT [$(_ResidentTable)];
Drop Table [$(_ResidentTable)];
_TableName=;
_ResidentTable=;
_Prefix=;
End Sub
Call CreateOrderTable('ClientOrder', 'client_orders', 'n1_co_');
Call CreateOrderTable('ClientAmend', 'client_amends', 'n2_ca_');
In general such sub-routine will work but all specified tables and fields must exists. For me it's not quite clear what do you want to reach with the prefix? Some kind of qualifying? If so the regular qualify-statement might be more practicable. I know that qualifying-approaches are very common within databases-logic but within a Qlik data-model it has IMO much more disadvantages then benefits - therefore you may re-think the usefulness of it.
Beside of this you may outsource this prefix-approach from the load-statement, means something like:
sub x(p1, p2, p3)
if '$(p3)' = 'x' then
let var = ...;
end if
load ... $(var) resident ...;
end sub
- Marcus