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 number of dates based on the status code

Hello!

any idea how to calculate the number of total days which are based on the status code.

I would like to show the total number of days of whose which are in StatusCode 02. (in script/set analysis?) 

StatusCodeStatusDateCount days 
02StatusA13.5.2017  
07StatusB4.9.2017114 
02StatusA2.12.2017  
07StatusB19.9.2018291 
02StatusA19.12.2018  
07StatusB1.2.201944 
02StatusA1.5.2019  
07StatusB30.5.201929 
   478StatusA days total
1 Solution

Accepted Solutions
sunny_talwar

You can also try this where you calculate the NoOfDays in the script and then use set analysis to show the count of only StatusCode = 02

Script

Table:
LOAD * INLINE [
    StatusCode, Status, Date
    02, StatusA, 13.5.2017
    07, StatusB, 4.9.2017
    02, StatusA, 2.12.2017
    07, StatusB, 19.9.2018
    02, StatusA, 19.12.2018
    07, StatusB, 1.2.2019
    02, StatusA, 1.5.2019
    07, StatusB, 30.5.2019
];

FinalTable:
LOAD *,
	 Alt(Previous(Date), Date) - Date as NoOfDays
Resident Table
Order By Date desc;

DROP Table Table;

 

and then use this expression

=Sum({<StatusCode = {'02'}>}NoOfDays)

image.png

View solution in original post

3 Replies
lironbaram
Partner - Master III
Partner - Master III

hi 

in your script after you loaded the table with status and date, for the example i'll call it Table1.

the write this part in your script 

Table2:

load * ,

           if(previous(StatusCode)=2,Date-Previous(Date) ) as Count_Days

resident Table1 

order by Date;

drop table Table1;

we use resident because it's the only way to use order by call

 

sunny_talwar

You can also try this where you calculate the NoOfDays in the script and then use set analysis to show the count of only StatusCode = 02

Script

Table:
LOAD * INLINE [
    StatusCode, Status, Date
    02, StatusA, 13.5.2017
    07, StatusB, 4.9.2017
    02, StatusA, 2.12.2017
    07, StatusB, 19.9.2018
    02, StatusA, 19.12.2018
    07, StatusB, 1.2.2019
    02, StatusA, 1.5.2019
    07, StatusB, 30.5.2019
];

FinalTable:
LOAD *,
	 Alt(Previous(Date), Date) - Date as NoOfDays
Resident Table
Order By Date desc;

DROP Table Table;

 

and then use this expression

=Sum({<StatusCode = {'02'}>}NoOfDays)

image.png

Arto_Kukkonen
Contributor II
Contributor II
Author

Wau  Thanks a lot!