Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
wanyunyang
Creator III
Creator III

count number of months

I have a date 11/2017 and a year filter. I'm trying to count the number of months. I

f I select year 2016 in the filter, it returns 0. If select 2017, returns 2 (11/2017, 12/2017). If select 2018, it will count till today, so returns 7 (11/2017, 12/2017, 01/2018, 02/2018, 03/2018/, 04/2018, 05/2018).

What should the function be for this?

Thanks in advance!

8 Replies
sunny_talwar

I have a date 11/2017 and a year filter.

Where is this date coming from?

wanyunyang
Creator III
Creator III
Author

year(date) is the year filter.

sunny_talwar

My question was where is this date coming from

wanyunyang
Creator III
Creator III
Author

Just Nov 2017

sunny_talwar

Not sure I understand, is there a sample your can share to explain your problem?

jerem1234
Specialist II
Specialist II

You can try either of these:

=count({$*<Date = {'>=$(=date(date#('11/2017', 'MM/YYYY')))'}>}Date)

=count(if(Date>=date#('11/2017', 'MM/YYYY'), Date))

This assumes that your Date field is in the format of 'MM/YYYY' hence it is just a standard count. You might have to use distinct in your expression as well depending on your data:

=count(DISTINCT{$*<Date = {'>=$(=date(date#('11/2017', 'MM/YYYY')))'}>}Date)

I also assumed your date 11/2017 is hard-coded or a certain date you have in mind. If its dynamic, you might have to use variables and tweak the code.

Hope this helps!

rafatashiro
Contributor III
Contributor III

Hi,

U can try this:

Count( {<Date= {">=Date#(11/2017,'MM/YYYY')<=Max(Month))"}>} Month )

Anil_Babu_Samineni

May be this?

Count( {<Year_Month= {">=$(=MinString(Year_Month))<=$(=MaxString(Year_Month)))"}>} Month)

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