# New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Contributor II

## Finding Cycles

Hi,

I need below req' in Qlik.

Thanks,

ID Data Output Output should be
222 AB Cycle1 Cycle1
222 AB Cycle2 Cycle2
222 AB Cycle3 Cycle3
222 e Cycle4 Cycle3
222 ffg Cycle4 Cycle3
222 aa Cycle4 Cycle3
222 ff Cycle4 Cycle3
222 df Cycle4 Cycle3

but in other scenario it coming correctly
ID Data Output
111 a Cycle1
111 b Cycle1
111 c Cycle1
111 d Cycle1
111 AB Cycle1
111 j Cycle2
111 k Cycle2
111 AB Cycle2
111 kl Cycle3
111 hg Cycle3
111 hgg Cycle3
111 AB Cycle3

Labels (2)

• ### sunny_talwar

17 Replies
Valued Contributor III

## Re: Finding Cycles

if(match('222'),'111')

try

Channa
MVP

## Re: Finding Cycles

Can you explain what is going on?

Contributor II

## Re: Finding Cycles

This is the Data
ID Data
111 a
111 b
111 c
111 d
111 AB
111 j
111 k
111 AB
111 kl
111 hg
111 hgg
111 AB
222 a
222 c
222 d
222 e
222 AB
222 aa
222 ff
222 AB
this is required Output
Output
Cycle1
Cycle1
Cycle1
Cycle1
Cycle1
Cycle2
Cycle2
Cycle2
Cycle3
Cycle3
Cycle3
Cycle3
Cycle1
Cycle1
Cycle1
Cycle1
Cycle1
Cycle2
Cycle2
Cycle2
MVP

## Re: Finding Cycles

What is the logic here?

Contributor II

## Re: Finding Cycles

Last time we tried this
*,
If(ID = Previous(ID), If(Previous(Data) = 'AB', RangeSum(Peek('CycleNum'), 1), Peek('CycleNum')), 1) as CycleNum,
'Cycle' & If(ID = Previous(ID), If(Previous(Data) = 'AB', RangeSum(Peek('CycleNum'), 1), Peek('CycleNum')), 1) as Output;
ID, Data
111, a
111, b
111, c
111, d
111, AB
111, j
111, k
111, AB
111, kl
111, hg
111, hgg
111, AB
222, a
222, c
222, d
222, e
222, AB
222, aa
222, ff
222, AB
];
but above mentioned mismatch coming .
Highlighted
Contributor II

## Re: Finding Cycles

if starting 3 rows has AB value it should show lik 3 cycles but it showing 4 cycles
Valued Contributor III

## Re: Finding Cycles

when cycle3,and cycle 2 should start

Channa
Contributor II

## Re: Finding Cycles

based on( Data = 'AB' is 1 cycle)
MVP

## Re: Finding Cycles

This is what I get when I run your script... what is the issue?