# QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements

Not applicable

## Creating Average for Last 24 Months Based on Date Selected

Hi all,

I need to calculate average of past 24 months based on Date Selected.

well the scenario is if the selected date is 12/Aug/2015 then i need to get all the values between 12/Aug/2015 and 12/Aug/2012 and Averaged those 24 Months Data.

Thanks.

1 Solution

Accepted Solutions
Contributor III

Try

6 Replies
Contributor III

Try

MVP

## Re: Creating Average for Last 24 Months Based on Date Selected

EDITED:

Are you looking for 36 Months data or 24 Months?

Use something as below for 24 Months

MVP

## Re: Creating Average for Last 24 Months Based on Date Selected

Try like this

Celambarasan

Honored Contributor III

MVP & Luminary

## Re: Creating Average for Last 24 Months Based on Date Selected

If it is 12/Aug/2015 and 12/Aug/2012

Sum({<YearFieldName=, QuarterFieldName=, MonthFieldName=, DateFieldName={">=\$(=AddMonths(Max(DateFieldName), -36))<=\$(=Date(Max(DateFieldName)))"}>} Sales)/36

If it last 24 months then use

Sum({<YearFieldName=, QuarterFieldName=, MonthFieldName=, DateFieldName={">=\$(=AddMonths(Max(DateFieldName), -24))<=\$(=Max(DateFieldName))"}>} Sales)/24

Hopw this helps you.

Regards,

Jagan.

Contributor II

## Re: Creating Average for Last 24 Months Based on Date Selected

Attached is a sample hop this helps

Community Browser