Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
m_torabi
Partner - Contributor
Partner - Contributor

Load Fields only if they exist

In Qlikview, I want to Load a table with the name of fields that I already know: field1, field2, ....

The table I am reading from may or may not contain on of the above fields. I want to set a predefined value (for example 0) for a field if it doesn't exist.

Could you add some comment and tell me how can I improve my code?


Example:

Source table:

Source table

My list of fields:

  1. Field1
  2. Field2
  3. Field3
  4. Field4

My desired result:

My desired result


I wrote a code for it:

  InlineTable: LOAD * INLINE [ Field1, Field2, OtherField1, OtherField2 1, 4, 7, 10 2, 5, 8, 11 3, 6, 9, 12 ]; SignTable: load if (FieldNumber('Field1','InlineTable')=0,0,Field1) as Field1, if (FieldNumber('Field2','InlineTable')=0,0,Field2) as Field2, if (FieldNumber('Field3','InlineTable')=0,0,Field3) as Field3 resident InlineTable; drop table InlineTable; 

but it gives an error:

Error

1 Solution

Accepted Solutions
sunny_talwar

Try this

InlineTable:

LOAD * INLINE [

    Field1, Field2, OtherField1, OtherField2

    1, 4, 7, 10

    2, 5, 8, 11

    3, 6, 9, 12

];


LET vField1 = if(FieldNumber('Field1','InlineTable') = 0, 0, 'Field1');

LET vField2 = if(FieldNumber('Field2','InlineTable') = 0, 0, 'Field2');

LET vField3 = if(FieldNumber('Field3','InlineTable') = 0, 0, 'Field3');


SignTable:

LOAD $(vField1) as Field1,

$(vField2) as Field2,

$(vField3) as Field3

Resident InlineTable;


DROP Table InlineTable;

View solution in original post

1 Reply
sunny_talwar

Try this

InlineTable:

LOAD * INLINE [

    Field1, Field2, OtherField1, OtherField2

    1, 4, 7, 10

    2, 5, 8, 11

    3, 6, 9, 12

];


LET vField1 = if(FieldNumber('Field1','InlineTable') = 0, 0, 'Field1');

LET vField2 = if(FieldNumber('Field2','InlineTable') = 0, 0, 'Field2');

LET vField3 = if(FieldNumber('Field3','InlineTable') = 0, 0, 'Field3');


SignTable:

LOAD $(vField1) as Field1,

$(vField2) as Field2,

$(vField3) as Field3

Resident InlineTable;


DROP Table InlineTable;