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: 
Not applicable

Flag every other week

Is there a way to flag every other week?

Here is an example of what I want to do. Every other week is labeled City. An inline with an if statement of some sort? What function could I use?

DATEDAYCITY/NON CITY
1/1/2008TUESDAYNON
1/2/2008WEDNESDAYNON
1/3/2008THURSDAYNON
1/4/2008FRIDAYNON
1/5/2008SATURDAYNON
1/6/2008SUNDAYCITY
1/7/2008MONDAYCITY
1/8/2008TUESDAYCITY
1/9/2008WEDNESDAYCITY
1/10/2008THURSDAYCITY
1/11/2008FRIDAYCITY
1/12/2008SATURDAYCITY
1/13/2008SUNDAYNON
1/14/2008MONDAYNON
1/15/2008TUESDAYNON
1/16/2008WEDNESDAYNON
1/17/2008THURSDAYNON
1/18/2008FRIDAYNON
1/19/2008SATURDAYNON
1/20/2008SUNDAYCITY
1/21/2008MONDAYCITY
1/22/2008TUESDAYCITY
1/23/2008WEDNESDAYCITY
1/24/2008THURSDAYCITY
1/25/2008FRIDAYCITY
1/26/2008SATURDAYCITY
1/27/2008SUNDAYNON
1/28/2008MONDAYNON
1/29/2008TUESDAYNON
1/30/2008WEDNESDAYNON
1/31/2008THURSDAYNON
1 Solution

Accepted Solutions
johnw
Champion III
Champion III

Do you want a chart expression?  Maybe something like this:

if(weekstart(DATE)=weekstart(above(DATE)),above("CITY/NON CITY"),if(above("CITY/NON CITY")='NON','CITY','NON'))

In the script, it would be similar, maybe something like this in your calendar table:

if(weekstart(DATE)=weekstart(previous(DATE)),peek("CITY/NON CITY"),if(peek("CITY/NON CITY")='NON','CITY','NON')) as "CITY/NON CITY"

View solution in original post

7 Replies
johnw
Champion III
Champion III

Do you want a chart expression?  Maybe something like this:

if(weekstart(DATE)=weekstart(above(DATE)),above("CITY/NON CITY"),if(above("CITY/NON CITY")='NON','CITY','NON'))

In the script, it would be similar, maybe something like this in your calendar table:

if(weekstart(DATE)=weekstart(previous(DATE)),peek("CITY/NON CITY"),if(peek("CITY/NON CITY")='NON','CITY','NON')) as "CITY/NON CITY"

Not applicable
Author

Script, I need users to be able to reuse the expression. I will try these and see if it fits my need. thanks

Not applicable
Author

Okay, so really close. So it looks like their week starts on a sunday, not monday. What would need to be changed?

Not applicable
Author

I just needed to add +1 to the Date and it worked like I expected. Thanks John!

johnw
Champion III
Champion III

The third parameter of the weekstart() lets you say which day the week starts on.  For weeks starting on Sunday, use weekstart(Date,0,-1).  Adding a day might be sufficient in your case, but it's probably good to get in the habit of using the QlikView functions.  No big deal, though.  Just wanted to point it out.

Not applicable
Author

If this satisfies your requirement it would be a little simpler. You could try an odd or even week approach    =if(odd(week(DATE)),'CITY','NON')

johnw
Champion III
Champion III

The week() function doesn't have a parameter to allow it to start on Sunday, though perhaps the +1 cheat is fine since we don't actually care what the week number is.  But then we have the problem where it won't always flag every other week because sometimes the year ends with week 53.