Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
fvelascog72
Partner - Specialist
Partner - Specialist

Where field problem

Hi all,

I have a question:

In this sample script:

DATA:

LOAD

  *

Inline [

Campo1, Valor1

AAA, 111

BBB,222

]

;

DATA2:

LOAD

  Campo1,

  Valor1

Resident DATA

Where Campo2 = 'AAA'

;

DROP Table DATA;

Can I put a IF condition in WHERE to let the two names (Campo1 and Campo2)?

The problem is when loading some excel files in a loop, the field name is changing.

Thank you.

13 Replies
Peter_Cammaert
Partner - Champion III
Partner - Champion III

IMHO this is the best approach. The others are just workarounds.

Good luck,

Peter

fvelascog72
Partner - Specialist
Partner - Specialist
Author

What do you think about this solution:

DATA:

LOAD

  *

Inline [

Campo1, Valor1

AAA, 111

BBB,222

]

;

LET vFile = FieldName(1,'DATA');

DATA2:

LOAD

  $(vFile) as "Campo2",

  Valor1

Resident DATA

Where $(vFile) = 'AAA'

;

DROP Table DATA;

For the other script:

For Each vFile in filelist *


     DATA:

     LOAD

          *

     FROM [$(vFile)];


     LET vFile = FieldName(1,'DATA');


     DATA2:

     LOAD

          Max(Floor([Creada]))          as "Max_Fecha"

     Resident DATA

     Where NOT $(vFile) like 'Generado*';


Next vFile;


Need to load the objetive field in first position.

Peter_Cammaert
Partner - Champion III
Partner - Champion III

If you're sure that it's always the first column that you'll use in a WHERE clause, then that will work too. The only thing is that performance will not be ideal, but that isn't much of a problem if your Excel files aren't too big.

BTW In the FOR loop, add a DROP Table DATA; statement after the LET vFile... line or you may be joining all columns from all Excel files into a single DATA table. I'm assuming that the autoconcatenate that will happen on your DATA2 table is intended?

Peter

fvelascog72
Partner - Specialist
Partner - Specialist
Author

The excel files aren´t big.

The loop of the example is a little part of the load.

Thank you very much.