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: 
Not applicable

Fill a field with a part of a file name

Hi,

I have a '.txt' file with some fields which are loaded to qlik view without problem.

The '.txt' file name is 'REAL_2015_12'.

When I load the file I would like to know how to add  (in addition to the fields loaded from the file), three more fields:

Field named 'Scenario' containing the unique value 'REAL'

Field named 'Year' containing the unique value '2015'


Field named 'Period' containing the unique value '12'


How coulda I do tihs?


Thanks



1 Solution

Accepted Solutions
sunny_talwar

May be this:

LOAD *,

          'REAL' as Scenario,

          2015 as Year,

          12 as Period

FROM REAL_2015_12.txt

Or if this need to be grabbed from the filename itself, then this:

LOAD *,

          SubField(FileName(), '_', 1) as Scenario,

          SubField(FileName(), '_', 2) as Year,

          Replace(SubField(FileName(), '_', 3), '.txt', '') as Period

FROM REAL_2015_12.txt

View solution in original post

3 Replies
sunny_talwar

May be this:

LOAD *,

          'REAL' as Scenario,

          2015 as Year,

          12 as Period

FROM REAL_2015_12.txt

Or if this need to be grabbed from the filename itself, then this:

LOAD *,

          SubField(FileName(), '_', 1) as Scenario,

          SubField(FileName(), '_', 2) as Year,

          Replace(SubField(FileName(), '_', 3), '.txt', '') as Period

FROM REAL_2015_12.txt

Gysbert_Wassenaar

LOAD

     *,

     subfield(Filebasename(),'_',1) as Scenario,

     subfield(Filebasename(),'_',2) as Year,

     subfield(Filebasename(),'_',3) as Period

FROM

     REAL_2015_12.txt (....etc)

     ;


talk is cheap, supply exceeds demand
Not applicable
Author

The second option thanks a lot to everybody.