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: 
RoyBatty
Contributor III
Contributor III

Expression to display measure for previous month only

Hi,

We have the following table:

messages:
LOAD
    country,
    message_count,
    client_cost,
    sent_month
FROM [lib://QVDFOLDER/messages.qvd] (qvd);

sent_month is a Date in format MMM YYYY (e.g. Jun 2025) :

RoyBatty_3-1752518614268.png

and Data model viewer shows the following tags:

RoyBatty_0-1752517530971.png

On the sheet we added a table, and as the first column (dimension) we added country.

Now we want to add a new column (measure) that will display Sum([message_count]) for the previous month only

We tried using the following expression:
Sum({<[sent_month] = {"=$(Date(MonthStart(AddMonths(Today(), -1)), 'MMM YYYY'))"}>} message_count)

But it doesn't work:

RoyBatty_1-1752518147551.png

We checked the data and there are messages that were sent in the previous month, but when we use the above expression - it shows an empty table. 

We tested this part of the expression by adding it to be a label - and it works:

Date(MonthStart(AddMonths(Today(), -1)), 'MMM YYYY')

RoyBatty_2-1752518379316.png

Do you know why the above expression doesn't work, what might need to be changed to make it work?

Labels (2)
1 Solution

Accepted Solutions
RoyBatty
Contributor III
Contributor III
Author

This works (the problem was with the quotes): 

Sum({<[sent_month] = {"$(=Date(MonthStart(AddMonths(Today(), -1)), 'MMM YYYY'))"}>} message_count)

(and also with missing "="... Thanks @Digvijay_Singh !)

View solution in original post

3 Replies
Digvijay_Singh

Try this may be - 

Sum({<[sent_month] = {"=$(=Date(MonthStart(AddMonths(Today(), -1)), 'MMM YYYY'))"}>} message_count)

 

Check in the expression editor at the bottom, it should show right value of the expression used in sent_month.

Somehow formatting should match between data model value and the value resulting from the above expression. Check for decimal component in the date as well, sometimes that causes the mismatch.

RoyBatty
Contributor III
Contributor III
Author

I tried that  and now the editor shows June 2025 (please ignore the "msg." prefix - I've excluded it here for simplicity):

RoyBatty_0-1752583534562.png

but for some reason it still doesn't work:

RoyBatty_1-1752583719834.png

 

 

 

 

 

RoyBatty
Contributor III
Contributor III
Author

This works (the problem was with the quotes): 

Sum({<[sent_month] = {"$(=Date(MonthStart(AddMonths(Today(), -1)), 'MMM YYYY'))"}>} message_count)

(and also with missing "="... Thanks @Digvijay_Singh !)