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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Count Month

Hi,

Below expression returns Jan 2008 to jun 2008. I need to count the no. of month between them:

MonthName(YearStart(Date#( Year(Today())-1, 'YYYY') )) &' to '& month(addmonths(Today(),-1)) &' ' &(Year(Today())-1)

If possible, let me know some other way to calculate no. of months between starting of year to lst month as done above.

Thanks,

Sunil

3 Replies
disqr_rm
Partner - Specialist III
Partner - Specialist III

Wouldn't that be same as number of last month, like 6 for june, since you are always workign with current year only?

If this is correct, you can get that by using: num(month(addmonths(Today(),-1)))

Hope I answered what you are looking for.

Not applicable
Author

Sunil,

Because Months are usually stored as a Dual (meaning they have both a numeric and a text representation) you can actually just subtract them to find the number fo months between them. A work of caution though, this only works if you are staying in the same year. If you are crossing years you must account for that.

So, given your example, something like this should work:


Month(AddMonths(Today(),-1)) - Month(YearStart(Today()))


This will give you the number of months between last month and the start of the year.

Thanks

sjprows

disqr_rm
Partner - Specialist III
Partner - Specialist III

Month(YearStart(Today())) is always 1 so you might hard code it as 1.