Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
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: 
pinheirf
Contributor
Contributor

Creating a new dynamic column in the script

Olá, estou precisando de ajuda para via script realizar a contagem de caracter "|" de um campoEndereços e em sequência separar esse campoEndereços em diversos camposEndereçoX.

exemplo do campoEndereços: 

Av. Wilson Alvarenga de Oliveira, 410 Viúva 35970-000 (31) 3837-7450 Barão de Cocais |
Rua Quinze de Novembro, 200 Centro 36200-740 (32) 3052-4200 Barbacena |
Av. Governador Bias Fortes, 841 Caminho Novo 36204-168 (32) 3339-5150 Barbacena |
Rua Tupinambás, 462 Centro 30120-700 (31) 3217-1151 Belo Horizonte |
Av. Afonso Vaz de Melo, 399 Barreiro 30640-700 (31) 3389-6300 Belo Horizonte

Tentei sem sucesso azer assim:

[Plan1]:
LOAD
[A] AS [Ends],
Len([Ends]) - Len(Replace([Ends], '|', '')) + 1 as NumEnds
Resident ;

FOR i = 1 TO NumEnds
LET Campoendereco = Peek('Ends', $(i) - 1);
Campoendereco:
LOAD
Trim(SubField(Campoendereco, '|', $(i))) as Ends_$(i)
Autogenerate 1;
NEXT

Labels (2)
1 Solution

Accepted Solutions
srchagas
Creator III
Creator III

Hi

try this code

tmp:
Load 
pessoa,
ends as Ends,
substringcount(ends,'|') As ContFields
;
LOAD
    pessoa,
    ends
FROM [lib://AttachedFiles/TestLoad.xlsx]
(ooxml, embedded labels, table is Sheet1);


 vL.tbnum = NoOfRows('tmp');
 
 for x = 0  to $(vL.tbnum) -1
 
 	vL.Num = peek('ContFields',$(x),'tmp')
 	
    	for  y = 1 to $(vL.Num)
        
        Pessoa_end:
        Load
        	pessoa,
            SubField(Ends,'|', $(y))	As Endereco
        resident tmp
        ;
               
        next y;
 	
 
 next x;
 
 drop Table tmp;

 

 

View solution in original post

2 Replies
srchagas
Creator III
Creator III

Hi

try this code

tmp:
Load 
pessoa,
ends as Ends,
substringcount(ends,'|') As ContFields
;
LOAD
    pessoa,
    ends
FROM [lib://AttachedFiles/TestLoad.xlsx]
(ooxml, embedded labels, table is Sheet1);


 vL.tbnum = NoOfRows('tmp');
 
 for x = 0  to $(vL.tbnum) -1
 
 	vL.Num = peek('ContFields',$(x),'tmp')
 	
    	for  y = 1 to $(vL.Num)
        
        Pessoa_end:
        Load
        	pessoa,
            SubField(Ends,'|', $(y))	As Endereco
        resident tmp
        ;
               
        next y;
 	
 
 next x;
 
 drop Table tmp;

 

 

pinheirf
Contributor
Contributor
Author

Muito obrigado pela ajuda. Funcionou! agora os campos podem ser separados.

 Capturarends.PNG