Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
JMAROUF
Creator II
Creator II

increment value after any change

Hi everyone,

i want to increment a value after any variable's change, i've used autonumber(FIELD1,FIELD2) it works but when FIELD1 gets the first value  autonumber gives the old value example:

field1  | field1 | number

xx              val          1

yy             val           2

xx             val            1

and this is what i want to do:

xx              val          1

yy             val           2

xx             val            3

 

Thank you for advance;

 

Labels (2)
1 Solution

Accepted Solutions
Taoufiq_Zarra

Hello @JMAROUF 

you can also do :

Data:


load *,if(rowno()=1,1,if(previous(Intermediate&'_'&policy)=Intermediate&'_'&policy,peek(number),(peek(number)+1))) as number
inline [
Intermediate,policy,date
xx,val,01/01/2016

xx,val,01/01/2017

yy,val,01/01/2018

yy,val,01/01/2019

xx,val,01/01/2020
]

 

output :

Capture.PNG

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉

View solution in original post

5 Replies
Taoufiq_Zarra

One solution for example :

Table1:

load *,if(rowno()=1,1,peek(number)+1) as number
inline [
field1,field2
xx,val
yy,val 
xx,val
]

 

output:

Capture.PNG

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
JMAROUF
Creator II
Creator II
Author

Hi Taoufiq,

Thank you so much for your answer, i've used autonumber() because i have some polices which change intermediate (SLOWLY CHANGING DIMENSION):

 field1  | field1 |  date

xx              val           01/01/2015

xx              val           01/01/2016

yy             val            01/01/2017

yy             val            01/01/2018

yy             val           01/01/2019

xx             val            01/01/2020

 

AND WANT THIS:

 field1  | field1 | number | date

xx              val          1             01/01/2015

xx              val          1             01/01/2016

yy             val           2              01/01/2017

yy             val           2              01/01/2018

yy             val           2              01/01/2019

xx             val            3             01/01/2020

JMAROUF
Creator II
Creator II
Author

Hello @Taoufiq_Zarra ,

Thank you for your answer, i've used autonumber for the ( SLOWLY CHANGING DIMENSION), i have some polices which change the intermediate, ex:

Intermediate| policy| date

xx              val          01/01/2016

xx              val          01/01/2017

yy              val          01/01/2018

yy             val          01/01/2019

xx             val            01/01/2020

and this is what i want:

Intermediate| policy| date | number

xx              val          01/01/2016       1

xx              val          01/01/2017       1

yy              val          01/01/2018      2

yy             val          01/01/2019       2

xx             val            01/01/2020     3

Taoufiq_Zarra

Hello @JMAROUF 

you can also do :

Data:


load *,if(rowno()=1,1,if(previous(Intermediate&'_'&policy)=Intermediate&'_'&policy,peek(number),(peek(number)+1))) as number
inline [
Intermediate,policy,date
xx,val,01/01/2016

xx,val,01/01/2017

yy,val,01/01/2018

yy,val,01/01/2019

xx,val,01/01/2020
]

 

output :

Capture.PNG

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
JMAROUF
Creator II
Creator II
Author

Thank you @Taoufiq_Zarra , it works well.

Best regards;