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

Difference between dates in the same table

Hello all,

I have the following problem. I need to get the amount of days a car has been in a certain country. What I have to base me on is a table full of events structured like this:

CarnumberCountryDateEventType
1BELGIUM20/07/2012ENTRY
2FRANCE20/07/2012ENTRY
43GERMANY21/07/2012EXIT
5BELGIUM23/07/2012ENTRY
21NETHERLANDS22/07/2012EXIT
2BELGIUM25/07/2012ENTRY
2FRANCE25/07/2012EXIT
1BELGIUM25/07/2012EXIT
21NETHERLANDS26/07/2012ENTRY
2BELGIUM27/07/2012EXIT

The problem is that in this table the events do not always come in the right sequence, as I highlighted for car 2. Nevertheless I need to extract from this table how many days the car has been in Belgium and how many days it has been in France. Afterwards it is possible it could return to France and this should be counted seperately. Output should be like this (for car 2)

CarnumberCountryBeginEndTotal days
2FRANCE20/07/201225/07/20126
2BELGIUM25/07/201227/07/20123
2FRANCE27/07/2012--

I have been breaking my head for on this issue for the past few days, maybe someone could help me out on this with a fresh light on things, it shouldn't be so hard but maybe I am thinking the wrong way. Any help is greatly appreciated.

Thanks in advance

Niels

6 Replies
brenner_martina
Partner - Specialist II
Partner - Specialist II

Hi nils,

look at my example!

greetings from Munich

Martina

Not applicable
Author

Hi Martina,

Thank you very much for your help!!

The only problem I still face is when a car goes to the same country again. Like First to BELGIUM then to FRANCE en then back to BELGIUM. In your example it will give both enddates for the two times it was in FRANCE giving extra lines which I do not need.

Do you or anyone else have an idea how to solve this?

giakoum
Partner - Master II
Partner - Master II

maybe this will help

brenner_martina
Partner - Specialist II
Partner - Specialist II

Hi,

look at my example again

Greetings from Munich

Martina

Not applicable
Author

Hi Martina,

Thanks again, but there seems to be something wrong. The sum of days is 0 in all cases as you don't have an enddate defined now. I don't know why, script seems right.

brenner_martina
Partner - Specialist II
Partner - Specialist II

Hi nils,

pardon, you are right, I will correct and send you my example!