Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Andrey_Kosarev
Contributor II
Contributor II

Is it possible to pass a field as an parameter to FieldNumber function?

Hi everyone! 

I've come across the following issue: 

Initially a have a table the looks like this: 

 

Table1:

key_fieldfield1field2field3
key1value1value2value3

 

At some point of my load script I use the cross_table function on this table, so that the result is as follows:

Table2:

key_fieldattribute_fieldvalue
key1field1value1
key1field2value2
key1field3value3

 

Later on in my script I want to use column names (field1, field2, field3) and their respective values for building another table, the main difficulty is that they ought to be sorted in the order, in which  they come  as field names in the very first table.  When you apply the cross tab function, the order gets mixed up, so i tried to use the FieldNumber function in the following way: 

 

 

FieldNumber(attribute_field, 'Table1') as field_number

 

 

So i basically want the function to go through all the values in the attribute_field of Table2, find the respective column names in Table1 and return their numbers, which would solve my sorting problem.

But the function always returns zero, as if the fields with names "field1, ...2, ...3" don't exist in Table1, which can't possibly be true.

Moreover, if I pass the first argument as a string: 

FieldNumber('field1', 'Table1') as field_number

it works just fine.

 

Could you please give any hints about what I am doing wrong? 

 

 

Labels (3)
1 Reply
fosuzuki
Partner - Specialist III
Partner - Specialist III

Hi,

does your Table1 has a defined set of fieldX columns? If so, you could just add a left join with an inline table:

 

Left Join(Table2)

Load * inline [

attribute_field, field_number

field1,1

field2,2

field3,3];