Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Not applicable

How to write a variable?

Hi,

I have a variable $'(vMonthENDDATE)'= date(monthend(today(),0),'YYYYMMDD') which returns the value of 20161130(Current Month End date)

What should be the expression  if I want to create a variable to return the value of 20161031?(Previous Month end date)

6 Replies
tinaco110
Contributor III

Re: How to write a variable?

Hi Badhikari,

The expression will be:

date(monthend(today(), -1),'YYYYMMDD')

Which is pretty similar to yours, the difference is the -1 instead of zero.

praveenkumar_s
Contributor

Re: How to write a variable?

use $1 instead of $...

Thanks,

Praveen Kumar S

MVP
MVP

Re: How to write a variable?

maybe

the previous month end of current month end date

is 1 day before current month start

=date(monthstart(today()) -1, 'YYYYMMDD')

rgvavihs
Valued Contributor

Re: How to write a variable?

=Date(MonthStart(Today())-1,'YYYYMMDD')

stabdha91
New Contributor III

Re: How to write a variable?

You can try something like this.

vPriorMonthENDDATE = Addmonths(vMonthENDDATE,-1)

lech_miszkiewic
Honored Contributor III

Re: How to write a variable?

This will not work

For Example: 28th of February will return 28th of January which is not a month end. You would have to include MonthEnd formula again like:

vPriorMonthENDDATE = MonthEnd(Addmonths(vMonthENDDATE,-1))

I however would follow maxgro suggestion:

=date(monthstart(today()) -1, 'YYYYMMDD')



hth