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

How to calculate the first day of a different status

Hi! Please let me know what kind of loop? I have to make to calculate Count_Days value in script. Always the first Status_A date value and the first Status_B date value should pic up and calculate the days amount.

CustomerTransaction_dateStatus_AStatus_BCount_Days 
80031326907.9.20157.9.2015   
800313269031.12.201531.12.2015   
800313269029.2.201629.2.2016   
80031326901.6.20161.6.2016   
800313269019.9.2016 19.9.2016378= 19.9.2016 - 7.9.2015
800313269027.3.2017 27.3.2017  
80031326901.6.20171.6.2017   
80031326902.10.20172.10.2017   
80031326903.1.20183.1.2018   
800313269017.5.201817.5.2018   
80031326909.8.20189.8.2018   
800313269022.8.2018 22.8.2018447=22.8.2018 - 1.6.2017
800313269025.9.201825.9.2018   
800313269018.3.2019 18.3.2019174=18.3.2019 - 25.9.2018
80031326903.6.20193.6.2019   
80031326905.6.2019 5.6.20192=5.6.2019 - 3.6.2019
80031326906.6.2019 6.6.2019  
80031326906.8.20196.8.2019   
800313269019.8.2019 19.8.201913=19.8.2019 - 6.8.2019
    1014Total_days
Labels (1)
1 Solution

Accepted Solutions
Arthur_Fong
Partner - Specialist III
Partner - Specialist III

There you go:

clipboard_image_0.png

 

 Use min() function to get the minimum Date of status A based on the flags created using peek function.

Refer logic in qvw attached.

Thanks and regards,

Arthur Fong

View solution in original post

4 Replies
Arthur_Fong
Partner - Specialist III
Partner - Specialist III

There you go:

clipboard_image_0.png

 

 Use min() function to get the minimum Date of status A based on the flags created using peek function.

Refer logic in qvw attached.

Thanks and regards,

Arthur Fong

Brett_Bleess
Former Employee
Former Employee

See duplicate post for further information:

https://community.qlik.com/t5/QlikView-Scripting/How-to-calculate-the-first-day-of-a-different-statu...

Regards,
Brett

To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.
Arto_Kukkonen
Contributor II
Contributor II
Author

Brilliant!  I really appreciate your help. Thank you!

Saravanan_Desingh

One solutions.

SET DateFormat='D.M.YYYY';

tab1:
LOAD RowNo() As RowID,*, If(Status<>Peek(Status),RangeSum(Peek(K1),1),Peek(K1)) As K1 INLINE [
    CustometID, TransactionDate, Status
    8003132690, 7.9.2015, StatusA
    8003132690, 31.12.2015, StatusA
    8003132690, 29.2.2016, StatusA
    8003132690, 1.6.2016, StatusA
    8003132690, 19.9.2016, StatusB
    8003132690, 27.3.2017, StatusB
    8003132690, 1.6.2017, StatusA
    8003132690, 2.10.2017, StatusA
    8003132690, 3.1.2018, StatusA
    8003132690, 17.5.2018, StatusA
    8003132690, 9.8.2018, StatusA
    8003132690, 22.8.2018, StatusB
    8003132690, 25.9.2018, StatusA
    8003132690, 18.3.2019, StatusB
    8003132690, 3.6.2019, StatusA
    8003132690, 5.6.2019, StatusB
    8003132690, 6.6.2019, StatusB
    8003132690, 6.8.2019, StatusA
    8003132690, 19.8.2019, StatusB
];

Left Join(tab1)
LOAD K1, Date(Min(TransactionDate)) As DateA
Resident tab1
Where Status='StatusA'
Group By K1
;

Left Join(tab1)
LOAD K1-1 As K1, Date(Min(TransactionDate)) As DateB
Resident tab1
Where Status='StatusB'
Group By K1
;

tab2:
LOAD *, DateB-DateA As CountDays
Resident tab1;

Drop Table tab1;