inweek - script and chart function
This function returns True if timestamp lies inside the week containing base_date.
Syntax:
InWeek (timestamp, base_date, period_no[, first_week_day])
Arguments:
Example | Result |
---|---|
inweek ('12/01/2006', '14/01/2006', 0) | Returns True |
inweek ('12/01/2006', '20/01/2006', 0 ) | Returns False |
inweek ('12/01/2006', '14/01/2006', -1 ) | Returns False |
inweek ('07/01/2006', '14/01/2006', -1) | Returns True |
inweek ('12/01/2006', '09/01/2006', 0, 3) | Returns False Because first_week_day is specified as 3 (Thursday), which makes 12/01/2006 the first day of the week following the week containing 09/01/2006. |
Example:
Add the example script to your app and run it. To see the result, add the fields listed in the results column to a sheet in your app.
This example checks if an invoice date falls at any time in the fourth week after the week in base_date, by specifying period_no as 4.
TempTable:
LOAD RecNo() as InvID, * Inline [
InvDate
28/03/2012
10/12/2012
5/2/2013
31/3/2013
19/5/2013
15/9/2013
11/12/2013
2/3/2014
14/5/2014
13/6/2014
7/7/2014
4/8/2014
];
InvoiceData:
LOAD *,
InWeek(InvDate, '11/01/2013', 4) AS InWeekPlus4
Resident TempTable;
Drop table TempTable;
The resulting table contains the original dates and a column with the return value of the inweek() function.
The InvDate5/2/2013 falls within the week that is four weeks after the base_date: 11/1/2013.
InvDate | InWeekPlus4 |
---|---|
28/03/2012 | 0 (False) |
10/12/2012 | 0 (False) |
5/2/2013 | -1 (True) |
31/3/2013 | 0 (False) |
19/5/2013 | 0 (False) |
15/9/2013 | 0 (False) |
11/12/2013 | 0 (False) |
2/3/2014 | 0 (False) |
14/5/2014 | 0 (False) |
13/6/2014 | 0 (False) |
7/7/2014 | 0 (False) |
4/8/2014 | 0 (False) |