Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to create range of weks and month in same listbox for below table.

DateAB
01-Jan-2012210
15-Jan-2012415
30-Jan-1261
01-Oct-2011770
01-Dec-2011510

Hi,

For above table, I want to to create list box which will show below ranges for selection

Current week,

Last 2 weeks,

Last 4 weeks,

Current Month,

Last 8 weeks,

Last 52 weeks,

Current Year

Any suggestion to create such listbox will be really helpful to me.

1 Solution

Accepted Solutions
jonathandienst
Partner - Champion III
Partner - Champion III

Hi

Here is another approach. The inline load creates the ranges based on today's date and then joins the Range field to the calendar date field (CalDate in this script):

Let zToday = Today(1);

Ranges:

LOAD Range, Date(Evaluate(RangeStart)) As RangeStart, Date(Evaluate(RangeEnd)) As RangeEnd;

LOAD * INLINE [

Range;                     RangeStart;                     RangeEnd

Today;                     zToday;                          DayEnd(zToday)

Yesterday;                zToday-1;                          DayEnd(zToday-1)

This Week;                WeekStart(zToday);           WeekEnd(zToday)

Last Week;                WeekStart(zToday,-1);           WeekEnd(zToday, -1)

Last 2 Weeks;         WeekStart(today(1),-1);      WeekEnd(zToday)

This Month;               MonthStart(zToday);           MonthEnd(zToday)

Last Month;                   MonthStart(zToday,-1);           MonthEnd(zToday,-1)

Last Two Months;      MonthStart(zToday,-1);       MonthEnd(zToday)

This Year;                YearStart(zToday);                YearEnd(zToday)

Last Year;                YearStart(zToday,-1);           YearEnd(zToday,-1)

YTD;                         YearStart(zToday);               DayEnd(zToday-1)

Last YTD;               YearStart(zToday,-1);          AddYears(DayEnd(zToday-1), -1)

MTD;                         MonthStart(zToday);               DayEnd(zToday - 1)

Last MTD;               MonthStart(zToday, -1);          AddMonths(DayEnd(zToday-1), -1)

] (delimiter is ';');

JOIN (Ranges) IntervalMatch (CalDate) LOAD RangeStart, RangeEnd RESIDENT Ranges;

DROP FIELDS RangeStart, RangeEnd;

Add whatever other ranges that you might need. Now put the Range field in a list box...

Regards

Jonathan

Sorry about the formatting - the tabs are being scrambled when I paste...

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein

View solution in original post

3 Replies
Anonymous
Not applicable
Author

This is a situation where easier to create an example than to explain... 🙂

See attached.  I'm not sure I got the definition of the "Last N Weeks" right - used full weeks before the start of the current week - but it doesn't matter, you can adjust the rules any way you want.  And, I hope you can now create the "missing" ranges.

Regards,

Michael

jonathandienst
Partner - Champion III
Partner - Champion III

Hi

Here is another approach. The inline load creates the ranges based on today's date and then joins the Range field to the calendar date field (CalDate in this script):

Let zToday = Today(1);

Ranges:

LOAD Range, Date(Evaluate(RangeStart)) As RangeStart, Date(Evaluate(RangeEnd)) As RangeEnd;

LOAD * INLINE [

Range;                     RangeStart;                     RangeEnd

Today;                     zToday;                          DayEnd(zToday)

Yesterday;                zToday-1;                          DayEnd(zToday-1)

This Week;                WeekStart(zToday);           WeekEnd(zToday)

Last Week;                WeekStart(zToday,-1);           WeekEnd(zToday, -1)

Last 2 Weeks;         WeekStart(today(1),-1);      WeekEnd(zToday)

This Month;               MonthStart(zToday);           MonthEnd(zToday)

Last Month;                   MonthStart(zToday,-1);           MonthEnd(zToday,-1)

Last Two Months;      MonthStart(zToday,-1);       MonthEnd(zToday)

This Year;                YearStart(zToday);                YearEnd(zToday)

Last Year;                YearStart(zToday,-1);           YearEnd(zToday,-1)

YTD;                         YearStart(zToday);               DayEnd(zToday-1)

Last YTD;               YearStart(zToday,-1);          AddYears(DayEnd(zToday-1), -1)

MTD;                         MonthStart(zToday);               DayEnd(zToday - 1)

Last MTD;               MonthStart(zToday, -1);          AddMonths(DayEnd(zToday-1), -1)

] (delimiter is ';');

JOIN (Ranges) IntervalMatch (CalDate) LOAD RangeStart, RangeEnd RESIDENT Ranges;

DROP FIELDS RangeStart, RangeEnd;

Add whatever other ranges that you might need. Now put the Range field in a list box...

Regards

Jonathan

Sorry about the formatting - the tabs are being scrambled when I paste...

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable
Author

Hi Michael, Jonathan,

Thanks for providing the solutions. I have used Jonathen's solution successfully.

I don't know why Michael's solution didn't work for me though it created ranges. Ofcourse that is my task to find out and correct.

Thanks again for the help.