Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

SELECT THE LAST MONTH AND YEAR

Hi guys,

How do I get data only for the last month in expression? My variable month and year is a string.

I want to get something like that:

count( CONDITION SELECTED THE LAST MONTH AND YEAR , Value)

Thank in advance,

1 Solution

Accepted Solutions
johnw
Champion III
Champion III

I'm not sure what you mean by "My variable month and year is a string."

I would normally have my Month field defined like this:

date(monthstart(Date),'MMM YYYY') as Month

In that case, probably this:

count({<Month={'$(=date(max(Month),'MMM YYYY'))'}>} Value)

View solution in original post

3 Replies
johnw
Champion III
Champion III

I'm not sure what you mean by "My variable month and year is a string."

I would normally have my Month field defined like this:

date(monthstart(Date),'MMM YYYY') as Month

In that case, probably this:

count({<Month={'$(=date(max(Month),'MMM YYYY'))'}>} Value)

Anonymous
Not applicable
Author

Thank you again . It works!!!

The format is underline 'MMM YYYY'. Do you know why?

Regards,

johnw
Champion III
Champion III

So in the expression editor, it's underlining the 'MMM YYYY' as bad, but the expression works anyway?  If so, my guess is that the editor is getting confused by the use of single quotes, and it thinks that '$(=date(max(Month),' is a quoted string, and that '))' is a quoted string.  With that interpretation, MMM YYYY is just sitting in the middle of the expression where it thinks a comma belongs instead.  So it highlights it.  It's wrong about it being an error, but I can understand how it got confused.

When QlikView processes this, it will process the $(...) part before even looking at anything else.  At that point, the inner single quotes will be removed, and instead we'll have something like JAN 2011.  The single quotes around it will then work normally.