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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Tommmy
Contributor III
Contributor III

=num(month(today()-1))

Hi experts

I need the previous month for a measure. This expression is not working, it shows the current month and not the previous month.

 

Sum({<[Document Year]={$(=Year(Today()))},[Document Month]={$(=num(month(now()-1)))}>}
[Amount])

 

Any ideas?

Kind Regards, Thomas

Labels (3)
3 Replies
SchalkF
Contributor III
Contributor III

Hi,

Your '-1' is in the wrong bracket, you are taking today -1, instead of month -1.

(=num(month(now())-1))

 

Kind regards

 

Tommmy
Contributor III
Contributor III
Author

Thank you! This is correct.

A last question: Document Month for September is '09'. Today(Document Month) is '9'. How do I solve this difference?

[Document Month]={$(=(Today([Document Month]))-1)}>}

RafaelBarrios
Partner - Specialist
Partner - Specialist

hi @Tommmy 

that way your formula is going to fail when current or selected month is january

so, you better use something like addmonths()

https://help.qlik.com/en-US/qlikview/May2022/Subsystems/Client/Content/QV_QlikView/Scripting/DateAnd...

example:

=count({< dv_date={">=$(=monthstart(addmonths(today(),-1)))<=$(=addmonths(today(),-1))"} >} id_delivery)

RafaelBarrios_2-1665161977489.png

 

normally you should create variables for max and min value

vMaxDate = addmonths(today(),-1)

vMinDate = monthstart(addmonths(today(),-1))

use the '=' sign when defining the variable

and your measure could be like

=count({< dv_date={">=$(vMinDate )<=$(vMaxDate )"} >} id_delivery)

Best