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

For each...next. Customer start date and end date from acitivty history table.

Hi Guys,

I am not familiar with loops but I believe i need a foreach...next loop.

I am trying to take a table with customer activities such as subscribe, unsubscribe. From this i would like a start date and an end date BUT the problem is that i can't just use min and max because the customers may have multiple subscriptions. So I need to go through each user and use some logic to determine their start and their end date and create a row for this one subscription and then start a loop again for that customer and create another row for a second subscription if there is one.

If you are unable to help with the above -I am new to loops etc in Qlik and if anyone has any documentation explaining the syntax and uses of all the different type that would be great.

Even if you don't know the exact answer i am looking for the rough approach i would need to take.

Thanks again Qlik community.

Alex

4 Replies
vikasmahajan

Go through this link

Load Multiple excel sheets using For loop

&

Qlikview Load Multiple Excel Sheets (Concatenate & Join tables)

&

https://community.qlik.com/thread/252808

Vikas

Hope this resolve your issue.
If the issue is solved please mark the answer with Accept as Solution & like it.
If you want to go quickly, go alone. If you want to go far, go together.
PunamWagh
Contributor III
Contributor III

Not sure wat u r looking for bt u can try following-

Data:

load * inline [

type , customer , Date

subscribe , Abc , 8/10/2018

subscribe , Abc , 7/10/2018

subscribe , Abc , 6/10/2018

subscribe , Abc , 5/10/2018

];

final:

load Date(min(Date)) as Start_Date,

     date(Max(Date)) as End_Date,

     customer

Resident Data

Group by customer;

drop Table Data;

exit script;


it will be great if u can provide sample data with expected output

alextomlins
Contributor III
Contributor III
Author

Hi Punam, 

i've done this as a resident load but the problem is that customers may have resubscribed later and then unsubscribed again under the same Customer ID. At the moment i am trying to do a for each...next loop to go through each customer id and create a row for each customer that details either first subscription or second subscription etc. I have no idea how to do it though

for now i am starting with just trying to use this 'for each next loop' to get the start date for each customers. at the moment i can only get the CustomerID in the loop. This is what i am using - how do i get another field value into it from the same table so that i can later apply some logic to them?

For each a in FieldValueList('CustomerID')

Data:

LOAD

'$(a)' & '-' & RecNo() as CustomerID

Autogenerate 1;

next a

Thanks,

Alex

alextomlins
Contributor III
Contributor III
Author

Hi these are slightly helpful but i was hoping to have more about evaluating field values using a for each loop?

I would actually like to find a way of bringing in multiple fields from other tables intto this bit of script;

For each a in FieldValueList('CustomerID')

Data:

LOAD

'$(a)' & '-' & RecNo() as CustomerID

Autogenerate 1;

next a