Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Count the number of iterations

  Hi

I got a simple file with a list of clients who are on double and i want to count the number of times that the client apparates (in an other field created). I know the autonumber function but it doesn' t do what i want.

I'd like a thing like that:

Client                      Champ_compté

Client 1                                1

Client 1                                2

Client 1                                3                            

Client 2                                1

Client 3                                 1

Client 3                                2

Client4                                 1

How can i do this?

Thanks a lot and excuse me for my bad english          

1 Solution

Accepted Solutions
tresesco
MVP
MVP

A bit simpler would be like:

Load

          Client,

          AutoNumber(RecNo(), Client) as Champ_compté

View solution in original post

7 Replies
tobias_klett
Partner - Creator II
Partner - Creator II

Hi,

I'm afraid it is not as simple as is looks like.

My suggestion is to loop over the distinct clients and generate your "Champ_compte" field. Concatenate all the Records and join them to the data.

NOTE: RecNo() is the number in the Source and RowNo() is the number in the resulting table.

Hope this helps

Regards Tobias

Not applicable
Author

Hi,

Use this expression in script

if(Client=peek(Client),NumSum(1,peek(i)) ,1) as i

Regards,

Amay

tresesco
MVP
MVP

A bit simpler would be like:

Load

          Client,

          AutoNumber(RecNo(), Client) as Champ_compté

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Something like this? A simple peek() call will add the required counter to an already sorted table. Make sure that your Client occurrences are sorted before applying this code:

RawData:

LOAD *, if (peek('Client') = Client, RangeSum(peek('Champ_compté'),1), 1) AS Champ_compté INLINE [

Client

Client 1

Client 1

Client 1

Client 2

Client 3

Client 3

Client4

];

Result:

CompterLesCLients thread152980.jpg

tobias_klett
Partner - Creator II
Partner - Creator II

Hi sab ben,

NOTE: To make sure Amay Patils solution is working correctly you have to load the Clients order by Client first. Because it is not able to deal with the same client occuring later on again.

Regards Tobias

Not applicable
Author

yess Thank you Tobias !!!!

Not applicable
Author

Yes thanks a lot peter but i didn't know the peek function!!

Thanks