Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

DevQlik
New Contributor II

Using Addmonths in IF Statement for Dimension

Hi,

I use this if statement but it does not bring back 2 months, it brings back all available months in a Year.

if(date#(GLPeriod.PeriodNameRP,'MMM-YY') >= $(=addmonths(date#(only(GLPeriod.PeriodName),'MMM-YY'),-2))
,date#(GLPeriod.PeriodNameRP,'MMM-YY'))

Please let me know if i did any wrong.

Thanks

Dev

 

Tags (1)
Labels (1)
1 Solution

Accepted Solutions
Highlighted
DevQlik
New Contributor II

Re: Using Addmonths in IF Statement for Dimension

It worked when i created the function as variable
vMonth5 variable is set with =addmonths(date#(only(GLPeriod.PeriodName),'MMM-YY'),-5)
and in IF
=if(date#(GLPeriod.PeriodNameRP,'MMM-YY') >= vMonth5
,date#(GLPeriod.PeriodNameRP,'MMM-YY'))

 

 

3 Replies
shwethaa
New Contributor III

Re: Using Addmonths in IF Statement for Dimension

Hi Dev,
Try below expression
if(Date(date#(GLPeriod.PeriodNameRP,'MMM-YY')) >= Date(addmonths(Date(date#(Min(GLPeriod.PeriodName),'MMM-YY')),-2))
,Date(date#(GLPeriod.PeriodNameRP,'MMM-YY')))


-Shwetha A
DevQlik
New Contributor II

Re: Using Addmonths in IF Statement for Dimension

Nope, it gives Error in Calculated Dimension. But the window says Expression is Ok.
Highlighted
DevQlik
New Contributor II

Re: Using Addmonths in IF Statement for Dimension

It worked when i created the function as variable
vMonth5 variable is set with =addmonths(date#(only(GLPeriod.PeriodName),'MMM-YY'),-5)
and in IF
=if(date#(GLPeriod.PeriodNameRP,'MMM-YY') >= vMonth5
,date#(GLPeriod.PeriodNameRP,'MMM-YY'))