Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
sai_12
Contributor III
Contributor III

Calculate difference between days from next record per categorical variable

Hello community,Hope you are all well

I have following data format where we have a client ,hotel they stayed ,first registered, stay from ,stay to

client hotel first registered stay_from  stay_to readmission
a itc 30/11/2022 30/11/2022 14/12/2022 yes
a itc 30/11/2022 30/12/2022 16/02/2023 yes
a taj 30/11/2022 16/02/2023 24/02/2023 no

 

If client is staying in a hotel from multiple times in a same hotel it is readmission in hotel,

eg:client a stayed in hotel itc from 30/11/2022 to 14/12/2022  and he then again came back to this place on 30/12/2022 and stayed here 16/02/2023

I am calculating this using this formula

=if(count(distinct total<client,hotel>client&hotel&stay_from )>1,'Yes','No')

Which gives gives me the above table,

I want to see if there was a readmission in 7 days which is i want to calculate (30/12/2022-14/12/2022 <=7 ) then yes else no, 

client hotel first registered stay_from  stay_to readmission Readmission in 7 days
a itc 30/11/2022 30/11/2022 14/12/2022 yes no
a itc 30/11/2022 30/12/2022 16/02/2023 yes no
a taj 30/11/2022 16/02/2023 24/02/2023 no no

 

I hope i was clear if not please let me know

Note: Please tell me how to approach this in front end, 

Labels (3)
1 Reply
Kushal_Chawda

@sai_12  try below

=aggr(if(stay_from-if(hotel=above(total hotel,1), Above(total stay_to,1))<=7,'yes','no'),client,hotel,(stay_from,(NUMETIC,ASCENDING)))