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

how to calculate average between two dates?

Hi,

I have two dates column..need to find average days between these two column..

Data as below:

  

CreateDate              DeliveryDate
3-Apr-1720-Apr-17
5-Apr-1718-Apr-17
5-Apr-176-Apr-17
4-Apr-1715-Apr-17
5-Apr-1710-Apr-17
5-Apr-1722-Jun-17
5-Apr-178-Apr-17

I use these formula both give same result:

=Round(Avg(DeliveryDate-CreateDate),0.01)

or

=Round(Avg(num(DeliveryDate,'#,##0')-num(CreateDate,'#,##0')),0.01)

Need assistance. Thanks in advance

8 Replies
Chanty4u
MVP
MVP

try this

Use   =Avg(Interval(DelDate-CreatDate,'D'))

mikaelsc
Specialist
Specialist

you want to calculate the avg per record, don't forget to AGGR (look this up, really, will be useful for your further dev)

avg(aggr(Sum(DeliveryDate-CreateDate),Record))

rubenmarin

Hi Sanjida, maybe dates are loaded as a string, not as dates, converting to date to make the calculation can be done as:

=Round(Avg(date#(DeliveryDate, 'D-MMM-YY')-date#(CreateDate, 'D-MMM-YY')),0.01)

Check the MonthNames variable at start of the script, the short name for months has to be the same as the data loaded.

Anil_Babu_Samineni

What output you need?

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
qlikviewwizard
Master II
Master II

Hi,

Please check this.

DataTemp:

LOAD *,num#(Interval(DeliveryDate-CreateDate,'D'),'###') AS NoOfDays;

LOAD date#(CreateDate,'DD-MMM-YY') as CreateDate,date#(DeliveryDate,'DD-MMM-YY') as DeliveryDate INLINE [

CreateDate,DeliveryDate

3-Apr-17,20-Apr-17

5-Apr-17,18-Apr-17

5-Apr-17,6-Apr-17

4-Apr-17,15-Apr-17

5-Apr-17,10-Apr-17

5-Apr-17,22-Jun-17

5-Apr-17,8-Apr-17

];

NoConcatenate

Data:

Load CreateDate,DeliveryDate,sum(NoOfDays)/2 as AverageDays,sum(NoOfDays) as NoOfDays Resident DataTemp

group by CreateDate,DeliveryDate;

drop table DataTemp;

Capture.JPG

Anonymous
Not applicable
Author

Number of days in average...

Anonymous
Not applicable
Author

Thanks...Maybe it will work...let me try 🙂

jakobjensen
Contributor II
Contributor II

what is "Record" referring to here?