Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Announcements
Qlik® Product Spotlight: Discover what’s possible. Get more from our products.
See for yourself. Register today.
william_fu
Contributor II

Calculate measure 4 months backward?

How can I calculate a measure that's always looking 4 months backwards?

i.e. October/17 in the chart needs to reflect the measure from June/17

5 Replies
aronwilliamson
Contributor

Re: Calculate measure 4 months backward?

In your expression add set analysis to show "month - 4"

i.e.

Sum({$<Month={'$(=Month-4)'}, Month=>} YourCalculation)

william_fu
Contributor II

Re: Calculate measure 4 months backward?

I tried the following and it didn't work:

Count({$<IndDesemb={'S'},DtInc-={'1/1/1900'},

[DtInc.autoCalendar.Month] ={'$(=[DtInc.autoCalendar.Month]-4)'},

[DtInc.autoCalendar.Month]=>} NroProposta)

Does it have to do with using autocalendar fields?

I also tried using the AddMonths function with no success

Khan_Mohammed
Honored Contributor II

Re: Calculate measure 4 months backward?

In your script create a Flag which will be Dynamic always

if(InMonth(DtInc, today() ,-4), 1, 0) as Last4Flag,

In front end use

Count({$<IndDesemb={'S'}, Last4Flag= {1}>} NroProposta)

aronwilliamson
Contributor

Re: Calculate measure 4 months backward?

Try:

Count({$< IndDesemb={'S'}, DtInc={'1/1/1900'}, [DtInc.autoCalendar.Month]={'$(=[DtInc.autoCalendar.Month]-4)'}>}, NroProposta)

The last part stops the calculation looking at month selection so removing this should do it.

[DtInc.autoCalendar.Month]=>} NroProposta)

atkinsow
Valued Contributor II

Re: Calculate measure 4 months backward?

Try

Count({$<IndDesemb={'S'},DtInc-={'1/1/1900'},

[DtInc.autoCalendar.Month] ={'$(=addmonths(max([DtInc.autoCalendar.Month]),-4)'},

[DtInc.autoCalendar.Month]=>} NroProposta)

The format of your month field could be an issue.  So you have some sample data?  you may have to do something like date(addmonths(max([DtInc.autoCalendar.Month]),-4),'M/D'YYYY')

Community Browser