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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[Help] Sequence Number from different file

Hi forum,
im very confused when i tried to make sequence number from some file. For example i have 2 files with same attribute but different name. i called first file "file xxx" and the second is "file zzz".
in file xxx i have attribut :
code|name
101|kaya
102|jennifer
103|shakira

and then in file zzz i have attribut :

code|name
101|kaya
102|jennifer
104|raisa

i want to make output :
in file xxx
id|code|name
1|101|kaya
2|102|jennifer
3|103|shakira

in file zzz
id|code|name
1|101|kaya
2|102|jennifer
4|104|raisa

i tried using tAggregateRow and using sequence number ("s1,1,1") to group by code but in different file, sequence number always add.
my wrong output :

in file xxx
id|code|name
1|101|kaya
2|102|jennifer
3|103|shakira

in file zzz
id|code|name
4|101|kaya
5|102|jennifer
6|104|raisa

Labels (2)
11 Replies
Anonymous
Not applicable
Author

Hi
You need to set a different sequence name for each file instead of a constant "s1", if you are using tFileList to iterate each file, you can set the sequence name with the global variable which counts the current file, for example: 
Numeric.sequence(((String)globalMap.get("tFileList_1_CURRENT_FILE")),1,1)
Anonymous
Not applicable
Author

2 sequences won't work for this I don't think Shong. It looks like thy want to tie the number to the code in both files. So if code 103 is awarded a 1 in one file, it will also have a 1 in the other file. The easiest way I can think of doing this is to do the following....

1) Create a routine.
2) Create a HashMap and an integer to keep track of the sequence in the routine.
3) For each code that is sent to the routine, check the HashMap to see if it exists. If it does not, add 1 to the sequence and store the current value of the sequence in the HashMap using the code as the key to the value. If it does exist, use the code to retrieve the value stored.
This will return the same sequence values between the files if the codes are the same.
Anonymous
Not applicable
Author

No 103 gets 3. 104 gets 4. The sequence is based on the code field - 100.
Anonymous
Not applicable
Author

I took it that that was a oversight of the example JanHess2. If not, then simply subtracting 100 would do.
Anonymous
Not applicable
Author

Hi shong i think it doesnt work, second sequence can start again from "1". I want sequence number based on the first sequence.

for rhall_2.0, can you give me an example code in routines? thank you for your reply
Anonymous
Not applicable
Author

Hi erbi  
Sorry, I read your question so quickly before, I think i understand your request know, as rhall_2.0 suggested, you need to hard code in a routine to return the sequence id based on the code field. 
Anonymous
Not applicable
Author

Hello,
As rhall_2.0 said , you can create a routine.
An example of routine can be this one I think :
package routines;

import java.util.HashMap;
import java.util.Map;

public class Sequences {
public static Map<Integer,Integer> map = new HashMap<Integer, Integer>();
public static Integer value = 0;

public static Integer getId(Integer code) {
if (! map.containsKey(code)){
value = value +1;
map.put(code, value);
}
return map.get(code);
}
}

When your routine had been created just call it in your tMap (the call is in this case : Sequences.getId(row1.code) )
I hope it will help you.
Anonymous
Not applicable
Author

Yeah, that would do it tdz (.......damn it, you got there first! 0683p000009MACn.png )
Anonymous
Not applicable
Author

rhall_2.0 wrote:
Yeah, that would do it tdz (.......damn it, you got there first! 0683p000009MACn.png )

Thank you and sorry rhall_2.0, next time I will let you give the solution first (moreover because it's your idea) 0683p000009MA9p.png