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

Announcements
Posting on Qlik Community is temporarily paused for some users. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Block of statement in tmap expression editior

Hi,

 

How to write a block of statement in tmap expression editor. I don't want to use extra component just because of some 2 extra statement. 

e,g , I am having 10 input records(record_no, id, name) and after each two record add some value to column and reset the record count, so for next two it will start will 1.

Input

id|name

1|abc

2|pqr

3|xyz

4|ccc

 

output

id|name|rec_num

1|abc|1

2|pqr|2

3|xyz|1

4|ccc|2

 

rec_number = if(Numeric.sequence("s1",1,1) % 2 !=0) { Numeric.sequence("s1",1,1)  }

else {

2 --> Assign 2 to 2nd row ;

Numeric.resetSequence("s1",1)--> Reset the sequence to 1  

}

 

For other assignment I am already using tmap but I have implement above logic too. How I can implement only using tmap.

I can achieve by using tjavarow, but one component I have to add which I don't want to add.

 

 

 

Labels (3)
1 Solution

Accepted Solutions
TRF
Champion II
Champion II

Hi,

A somewhat unusual way of doing things in tMap but you can write a block of code like that:

0683p000009LurL.png

 

Var.var1 is used to get the next value for sequence "s1".

Var.var2 value is forced to 1 (or any other value) for syntax. Be careful to the semicolumn after the 1 (usually there is no).

The 2nd line of code is here to reset the sequence "s1" to 0 if the curent value is even.

And the result is what you expect (I've added 2 lines just for testing):

0683p000009LurV.png

Hope this helps.

View solution in original post

2 Replies
TRF
Champion II
Champion II

Hi,

A somewhat unusual way of doing things in tMap but you can write a block of code like that:

0683p000009LurL.png

 

Var.var1 is used to get the next value for sequence "s1".

Var.var2 value is forced to 1 (or any other value) for syntax. Be careful to the semicolumn after the 1 (usually there is no).

The 2nd line of code is here to reset the sequence "s1" to 0 if the curent value is even.

And the result is what you expect (I've added 2 lines just for testing):

0683p000009LurV.png

Hope this helps.

cterenzi
Specialist
Specialist

I feel compelled to point out that using a sequence to fill in 1 or 2 is wasteful. If the previous value is 1, current value is 2, otherwise 1.