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

Calculation of Dates

I have the follow scenario:

ActivityStart_DateEnd_DateDuration (days)
Education31/12/201301/01/20141
Sports10/12/201314/12/20135
Shopping12/04/201312/05/201330
Others15/12/201316/12/20131
Sports12/03/201312/04/201331
Education12/02/201312/04/201359
Others12/02/201301/03/2014382

First i bring in these data from Excel and have them formatted to DD/MM/YYYY format.

When creating this straight table chart, i added in an expression to calculate the Duration through: (End_Date - Start_Date).

Next i would like to put this into a bar chart with a sum to calculate the total number of days the activity took.

Eg. Sports will be 5+31=36, Others will be 1+382=383 etc etc

Is there a single-line expression to do this? I tried having the following expression but it doesn't work:

Sum(TOTAL ( [End_Date] - [Start_Date] ) )

Can someone enlighten me please?

1 Solution

Accepted Solutions
chiru_thota
Specialist
Specialist

You can use below expression.You need correct the date format first as QV is considering few dates as text as highlighted.

sum(TOTAL <Activity>

DATE(MakeDate(Right(Trim(End_Date),4),SubField(End_Date,'/',2),SubField(End_Date,'/',1)),'DD/MM/YYYY') -

DATE(MakeDate(Right(Trim(Start_Date),4),SubField(Start_Date,'/',2),SubField(Start_Date,'/',1)),'DD/MM/YYYY') )

Date diff.jpg

View solution in original post

1 Reply
chiru_thota
Specialist
Specialist

You can use below expression.You need correct the date format first as QV is considering few dates as text as highlighted.

sum(TOTAL <Activity>

DATE(MakeDate(Right(Trim(End_Date),4),SubField(End_Date,'/',2),SubField(End_Date,'/',1)),'DD/MM/YYYY') -

DATE(MakeDate(Right(Trim(Start_Date),4),SubField(Start_Date,'/',2),SubField(Start_Date,'/',1)),'DD/MM/YYYY') )

Date diff.jpg