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

Comparison between the last state of a rental with the previous one

Hi everyone,

I'am dealing with a difficult in manipulating dates with Qlik sense.

I am trying to compare the last date of a rental with the previous one, and checking the state of the rental. Maybe it's not clear so i will give you an example to understand what i want to do. 

So I have this table to follow the rental of cars.

ID_carsID_transactionDate_statusstatusCountry
12205312/10/2005availableBrazil
12205412/11/2005rentedBrazil
12205505/12/2005availableBrazil
12205606/03/2007rentedBrazil
12205718/10/2008availableBrazil
13305001/02/2004rentedUK
13305102/03/2005availableUK
13305210/11/2006rentedUK
13305312/02/2007availableUK
13305413/10/2007rentedUK
14305514/05/2003rentedGermany
14305616/02/2005availableGermany
14305711/06/2008rentedGermany
14305810/10/2009availableGermany
14305914/10/2011rentedGermany

 

For each Id_cars I have the Id_transaction associated with the status (rented or available) and the date of the status. 

My goal is to calculate the last date of status and the previous one, and check that the status are not the same.

For example : 

ID_carsID_transactionlast_date_statuslast_statusPrevious_date_statusPrevious_statusCheck status
12205718/10/2008available  ok
122056  06/03/2007rented

ok

 

The second table, it's may be not the good representation but it was to give you an idea if what I want to do.

 

Thank you for your helping !

 

5 Replies
Kashyap_R
Partner - Specialist
Partner - Specialist

Hi

Please find the answer in attachment

Hope this helps

Thanks

Thanks and Regards
Kashyap.R
Kushal_Chawda

You can create straight table

Dimension:

ID_Cars

ID_Transaction

Expressions:

 

1) Latest Status
=aggr(FirstSortedValue(status,  -Date_status),ID_cars)

2) Latest Date
=aggr(FirstSortedValue(Date_status,  -Date_status),ID_cars)

3) Previous Date Status
=aggr(FirstSortedValue(status,  -Date_status,2),ID_cars)

4) Previous Status
=aggr(FirstSortedValue(Date_status,  -Date_status,2),ID_cars)

 

 

Note: In Data handling properties uncheck 'suppress zero values'

foxwhite
Contributor II
Contributor II
Author

Hi Kashyap,

 

I've tried your app, and it seem to be worked. 

In additonnaly i want to do a check for all transactions. I can't have successively the same status for an Id_car. The status can't not be "rented" and the previous one "rented"also.

For example :

ID_carsStatusDate_statusCheck
12available12/10/2005 
12rented12/11/2005ok
12available05/12/2005ok
12rented06/03/2007ok
12available18/10/2008ok

 

But it was this :

ID_carsStatusDate_statusCheck
12rented12/10/2005 
12available12/11/2005ok
12rented05/12/2005ok
12rented06/03/2007wrong
12available18/10/2008ok

 

The car is rented successively the 5/12/2005 and 06/03/2007 without beeing available between.  I can use the expression given in your app, but the main difficult is that the number of transactions per ID_cars is variable. For this example i have 5 transactions (so 5 status to check), but for another cars I can have more or less than this number.

If you can help me or someone else, that would be great.

Many thanks for your first solution.

 

Kashyap_R
Partner - Specialist
Partner - Specialist

Hi

Can u please share me the QVF file, I will try and get back to u

Thanks

Thanks and Regards
Kashyap.R
foxwhite
Contributor II
Contributor II
Author

Here the QVF File.

Thank you.