Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
soniasweety
Master
Master

not working

Hi @sunny_talwar 

where condition is not working in script..  below i am using.

where Date#(Calendar_Month,'YYYYMM')<=date(addmonths(today()-2,-45),'YYYYMM')

---Calendar_month  -- No months its showing  as DB there is  values for this CalendarMonth.

 

when i  hardcode the field its working.   like below

where Calendar_month<='201709';           ----- this is working.   

what might be the issue with first where condition?

how can i modify the where condition expression?

 

thanks

Labels (1)
  • month

3 Solutions

Accepted Solutions
tresesco
MVP
MVP

Try like:

Date#(Calendar_Month,'YYYYMM')<=addmonths(today()-2,-45)

 

And also note, 

Date(addmonths(today()-2,-45),'YYYYMM') = '201508'                  // Is this the value you want to compare with?

 

View solution in original post

marcus_sommer

I think your issue is that you want to compare "normal" numbers against dates (it are also numbers but a bit different - and independent from their formatting) and in this way they don't match.

To get your showed numbers you could use the following logic:

year(date) * 100 + month(date)

Quite similar and in your case probaly more suitable would be to use a consecutive YearMonth counter which could be created with:

year(date) * 12 + month(date)

and then you could use a where-clause like:

where year(date) * 12 + month(date) <= (year(today()-2) * 12 + month(today()-2)) - 45

Even more useful would be to add the above created YearMonth period-fields as standard fields within all your qvd's. It simplifies such where-clauses and provides also the possibility to pre-load the required time-frame within an autogenerate load like:

PeriodDummy: load (year(today()-2) * 12 + month(today()-2)) + 1 - recno() as Period autogenerate 45;

and the using a where exists() to keep the qvd-loading optimized like:

where exists(Period);

- Marcus

View solution in original post

sunny_talwar

When you say the condition is not working in the script? Do you mean it brings back no result? Or does it bring different number of records? This might make help if the number of records are different

Where Date#(Calendar_Month, 'YYYYMM') <= MonthStart(Today()-2, -45);

Because when you entered 201709... it automatically assumed  beginning of the month, but when you use AddMonths, it take you back 45 months to the exact date instead of beginning of the month. You can use MonthStart instead of AddMonths

View solution in original post

12 Replies
dplr-rn
Partner - Master III
Partner - Master III

try changing to below
Date(Calendar_Month,'YYYYMM')<=date(addmonths(today()-2,-45),'YYYYMM')
or
Date(Date#(Calendar_Month,'YYYYMM'),'YYYYMM')<=date(addmonths(today()-2,-45),'YYYYMM')
soniasweety
Master
Master
Author

Hi Dilipranjith 

 

both expressions not working 😞

Hi  

tresesco
MVP
MVP

Try like:

Date#(Calendar_Month,'YYYYMM')<=addmonths(today()-2,-45)

 

And also note, 

Date(addmonths(today()-2,-45),'YYYYMM') = '201508'                  // Is this the value you want to compare with?

 

soniasweety
Master
Master
Author

No.. its not like that.. i want to load the data beofre 45 months .. whatever comes under that condition it should in calender month field
tresesco
MVP
MVP

Have you tried the expression I suggested? Is your Calendar_Month field in YYYYMM format?
soniasweety
Master
Master
Author

Hi    yeah application is running in Qmc... once done i will update you.

 

and  calendar month format is   YYYYMM only.

soniasweety
Master
Master
Author

Hi 

 

marcus_sommer

You mention a DB in your description. If you tries to apply Qlik functions within the sql-query it will fail. In this case you need to apply functions which your database and the used driver supports or if the queried dataset isn't too large you could apply the condition within a preceeding load, like:

load * where Condition;
sql select * from DB;

- Marcus

soniasweety
Master
Master
Author

we have loaded full load to one qvd.. from that qvd we are dividing the multiple qvds.. there we are writing this where condtions .... so how to over come this?