15 Replies Latest reply: Feb 16, 2016 9:52 AM by Kaushik Solanki

# Last three months count in Month wise table

Hi All ,

I have a requirement I have to show Month wise customer count in table where in one expression need to display count of customer code and in next expression need to display customer count of  last 3 month in respect of that month .

For example if first row for Jan 2015 ,last 3 month count of customer would be Nov ,Dec and Jan .

in next row Feb 2015 ,last three month would be Dec ,Jan and Feb .

I used rangesum function but it is giving me sum of last 3 row which is incorrect  .

RangeSum(above(Count(distinct{<_Flag={'SD WOD_DOD'}>}CustomerCode),0,3))

then I pass condition for last 3 month in set analysis but it is giving same value as month wise value .

Count(distinct{< _Flag={'SD WOD_DOD'},CommonDate ={">=\$(=num(MonthStart(Date(Max(CommonDate)-90))))<=\$(=num(MonthStart(Date(Max(CommonDate)))))"}>}CustomerCode)

Please check both expresion which I used ,help me out .

If any another solution can be provided, would very helpful .

Chanchal

• ###### Re: Last three months count in Month wise table

try this?

=Count(distinct{< CommonDate= ,_Flag={'SD WOD_DOD'},

CommonDate ={">=\$(=Date(Max(CommonDate)-90,'DD/MMM/YYYY'))<=\$(=Date(Max(CommonDate),'DD/MMM/YYYY'))"} >} CustomerCode)

Note: Format of Common Date should be 'DD/MMM/YYYY'

• ###### Re: Last three months count in Month wise table

HI,

Second expression should work, but all you need to do is suppress the selections of other filters related to the year, month , quarter...

So your expression will be like below.

Count(distinct{< _Flag={'SD WOD_DOD'},CommonDate ={">=\$(=num(MonthStart(Date(Max(CommonDate)-90))))<=\$(=num(MonthStart(Date(Max(CommonDate)))))"}, Year = ,Month = , Quarter=>}CustomerCode)

Regards,

Kaushik Solanki

• ###### Re: Last three months count in Month wise table

Use of Num() will work only if CommonDate is into numeric form, else it will not work

• ###### Re: Last three months count in Month wise table

Hi All ,

Thanks a lot for quick response.

I have checked  expression share by both of you . But it is not giving correct answer .

I have attached output of data for reference please check column C and D.

Chanchal

• ###### Re: Last three months count in Month wise table

Hi,

Can you please upload sample application and also let us know what output you are looking for (With values)

Regards,

Kaushik Solanki

• ###### Re: Last three months count in Month wise table

Yes Sure ,

Also I have mentioned last  3 month values for 3 months .

 Dec Nov Oct 823 841 871

Chanchal

• ###### Re: Last three months count in Month wise table

Can you please explain how did you got the numbers like Dec 823..

What is the logic behind this.

Regards,

Kaushik Solanki

• ###### Re: Last three months count in Month wise table

Sure .

823 is distinct count of customer code of Dec ,Nov and Oct month for December.

In Excel I did this mannualy .

Same number I need in qlik in Last 3 months .

• ###### Re: Last three months count in Month wise table

Hi,

I have made some changes in script to make it work.

It cant be achieve using set analysis, because the Max or any other aggregate function in  set analysis is evaluated at overall level not at dimension level.

Hope this will solve your issue.

Regards,

Kaushik Solanki

• ###### Re: Last three months count in Month wise table

Hi Kaushik ,

I applied you solution it is giving last three month count .

But it is giving another challenge that is how do I show month wise count .

I have to show both in single table .

• ###### Re: Last three months count in Month wise table

Hi,

Change this script.

InterMediate:

'\$(vMonth)' as Show_Month_Chart,

If(InterMonth = '\$(vMonth)',1,0) as Flag

Resident CAL where InterMonth >= AddMonths(\$(vMonth),-2) and InterMonth <= \$(vMonth);

In chart Add below expression to get monthly count.

Count(Distinct {<_Flag={'SD WOD_DOD'},Flag = {"1"}>} CustomerCode)

Hope this will solve the issue.

Regards,

Kaushik Solanki

• ###### Re: Last three months count in Month wise table

Many Thanks Kaushik ,

If possible to you ,Please explain how this logic is working?

Chanchal

• ###### Re: Last three months count in Month wise table

HI Chanchal,

The logic goes like this.

1. You wanted last 3 months count, which as I had said was not possible with expressions in chart, so I have done modification in script and against each month I have mapped last 3 months. So using the new month you can easily get last 3 months count.

2. you wanted the Month wise count also, so I have created a flag which will select the current month from the mapping and thus you will get exact count for that month also.

Hope its clear.

Regards,

Kaushik Solanki

• ###### Re: Last three months count in Month wise table

Hi

I'am not sure to understand what do you mean by wise month ( due to my poor english )

But have a look to this post about accumulation :

https://community.qlik.com/blogs/qlikviewdesignblog/2015/11/09/accumulations

for your case it will be very usefull i think

Regards

Bruno

• ###### Re: Last three months count in Month wise table

Hi Chanchal,

Making use of master calendar should be the best way to go as it will even help with your performance.

Use inMonths() function to achieve the last 3 months flag and later this can be made use of in your calculations.

Thanks,

Sangram.