Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Consecutive count

Hi guys,

I just want to count only the consecutive values based on maximum month-year (from descending order).

For example, 5 months are consecutive in the below screenshot based on the maximum month-year (Dec-2017) descending order.

Here we don't have Jul-2017 after Aug-2017. So, the count will be 5.

Screenshot_1.png

Attached sample QVW and data in excel. Please help.

Regards,

Siva.

9 Replies
Anil_Babu_Samineni

That means, you want to count only for Max 5 months? May be


=Count({<[Month-Year] = {">=$(=AddMonths(Max([Month-Year]),-5))<=$(=Max([Month-Year]))"}>} [Month-Year])

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
petter
Partner - Champion III
Partner - Champion III

You can use this expression to calculate the number of consecutive months starting from the last month:

=Index(Concat(Aggr(-(AddMonths(Below(total [Month Year],1),-1)=AddMonths(Below(total [Month Year],2),-2)),ID,[Month Year]),'',-[Month Year]),'0',2)-1

It can be put as it is in a text box or as a title or caption.

Anonymous
Not applicable
Author

Thanks, Peter. It's working, but if year changes it's not working.

For example, after Jan-2018, it's not counting Dec-2017. Do we need to change the expression for it accordingly?

Also, I can't use this expression in straight table expressions. Please help.

Anonymous
Not applicable
Author

Hi Anil,

I need to count consecutive months not upto maximum 5 months. I need to calculate the number of consecutive months starting from the last month in a straight table expression.


Thanks,

Siva.

petter
Partner - Champion III
Partner - Champion III

I tested the expression with various dates and it worked well for me across years. I tested it specifically with both Jan-2018 and earlier... Are your dates real dates? The dates I tested with are actual dates - every month is based on being the 1st of every month.

petter
Partner - Champion III
Partner - Champion III

If you want it to work on each row in a straight table you just have to add total in the Concat function:

Index(Concat(total Aggr(-(AddMonths(Below(total YM,1),-1)=AddMonths(Below(total YM,2),-2)),ID,YM),'',-YM),'0',2)-1

I have attached the QlikView application so you can have a look.

Anil_Babu_Samineni

With TOTAL key it will help? Chek Petter solution which is updated

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
Anonymous
Not applicable
Author

Good day Guys

So sorry to resurrect this, please have mercy if im breaking any rules

How would the query change if the data and output changes the following?

examplexls.png

Anil_Babu_Samineni

Check there Count consecutive months.

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