Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
veronicahernand
Partner - Contributor III
Partner - Contributor III

subfield returns only first value in script

Hi,

I have  the following folder with qvds from different years and I need to extract the year (in the *) so I can create a loop for loading the qvds.

veronicahernand_2-1607493709886.png

veronicahernand_1-1607493631419.png

But the subfield doesn't work and it only extracts the value for the first row:

veronicahernand_0-1607493584441.png

Could you help me, please? Thanks!

 

 

Labels (3)
1 Solution

Accepted Solutions
veronicahernand
Partner - Contributor III
Partner - Contributor III
Author

Hi,

Finally I used this code:

set directory="lib://XXXXXXX";


for each file in filelist('$(directory)\Pedidos_*.qvd')

let año=subfield(subfield(file,'_',3),'.',1);

load 

*

from [lib://YYYYYYY/Pedidos_$(año).qvd]
(qvd);

next file;

 

but thank you all for your answers!!!!!!!

View solution in original post

8 Replies
Vegar
MVP
MVP

It looks correct to me. You could try to skip the  preceding load to see if that is causing your issue

Put the filename() function inside the substring in the original load. Does this improve the result? 

MayilVahanan

Hi @veronicahernand 

You can try like below

instead of subfield, you can try with right function also.

right(filename(), 8 )as firstpart

right('pedidos_2018.qvd', 8 ) <-- gives 2018.qvd

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
veronicahernand
Partner - Contributor III
Partner - Contributor III
Author

It didn't work...

Finally I had to do this:

veronicahernand_0-1607882845457.png

 

 

Anil_Babu_Samineni

Why you need another resident load, For me your script should work. Try this for a while and see

Subfield(filename, '_', -1)

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Kushal_Chawda

@veronicahernand  just one suggestion that use first 1 LOAD when you are loading filename from qvd using "*" so that it will fetch single record only and will not load full QVD data. 

veronicahernand
Partner - Contributor III
Partner - Contributor III
Author

You're absolutely right!!!! I have about 30M rows and the load gets very slow...  thank you!!!!!! 🙂 🙂

Anil_Babu_Samineni

If that issue resolved please mark other answer as accepted otherwise please post your answer and close this ticket.

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
veronicahernand
Partner - Contributor III
Partner - Contributor III
Author

Hi,

Finally I used this code:

set directory="lib://XXXXXXX";


for each file in filelist('$(directory)\Pedidos_*.qvd')

let año=subfield(subfield(file,'_',3),'.',1);

load 

*

from [lib://YYYYYYY/Pedidos_$(año).qvd]
(qvd);

next file;

 

but thank you all for your answers!!!!!!!