Load script
weekday can be used in a load script to return a string and a number representing a day of the week, even if FirstWeekDay and ReferenceDay are already set in the script. The load script below includes specific FirstWeekDay and ReferenceDay values and then uses weekday to return both strings and numbers that represent days of the week from the data in the transaction_date column.
In the results shown, the Day column contains the strings returned, while Numeric value of Day and Numeric value of week starting from Sunday contain the numeric values returned. In the load script weekday is multiplied by 1 as a simple way to make sure that the data type returned is numeric.
In the Data load editor, create a new section, and then add the example script and run it. Then add, at least, the fields listed in the results column to a sheet in your app to see the result.
SET DateFormat='DD/MM/YYYY';
SET TimestampFormat='DD/MM/YYYY h:mm:ss[.fff] TT';
SET FirstWeekDay=0;
SET BrokenWeeks=1;
SET ReferenceDay=0;
SET DayNames='Mon;Tue;Wed;Thu;Fri;Sat;Sun';
SET LongDayNames='Monday;Tuesday;Wednesday;Thursday;Friday;Saturday;Sunday';
Transactions:
Load
*,
WeekDay(transaction_date) as [Day],
1*WeekDay(transaction_date) as [Numeric value of Day]
1*WeekDay(transaction_date, 6) as [Numeric value of a week starting from Sunday],
;
Load * Inline [
transaction_id, transaction_date, transaction_amount, transaction_quantity, discount, customer_id, size, color_code
3750, 20180830, 12423.56, 23, 0,2038593, L, Red
3751, 20180907, 5356.31, 6, 0.1, 203521, m, orange
3752, 20180916, 15.75, 1, 0.22, 5646471, S, blue
3753, 20180922, 1251, 7, 0, 3036491, l, Black
3754, 20180922, 21484.21, 1356, 75, 049681, xs, Red
3756, 20180922, -59.18, 2, 0.333333333333333, 2038593, M, Blue
3757, 20180923, 3177.4, 21, .14, 203521, XL, Black
];
Results
Qlik Sense table showing results of the weekday function being used in the load script.
transaction_id |
transaction_date |
Day |
Numeric value of Day |
Numeric value for a week starting from Sunday |
3750 |
20180830 |
Thu |
3 |
4 |
3751 |
20180907 |
Thu |
3 |
4 |
3752 |
20180916 |
Sat |
5 |
6 |
3753 |
20180922 |
Fri |
4 |
5 |
3754 |
20180922 |
Fri |
4 |
5 |
3756 |
20180922 |
Fri |
4 |
5 |
3757 |
20180923 |
Sat |
5 |
6 |