makedate 可用在数据脚本中以将来自不同字段的日期数据组合成一个新的日期字段。在下面的示例,来自字段 transaction_year、transaction_month 和 transaction_day 的日数据被组合成名为 Transaction Date 的一个新字段。
在数据加载编辑器中,创建新的部分,然后添加示例脚本并运行它。然后,至少要将结果列中列出的字段添加到应用程序中的表格才能查看结果。
加载脚本
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
*,
MakeDate(transaction_year, transaction_month, transaction_day) as "Transaction Date",
;
Load * Inline [
transaction_id, transaction_year, transaction_month, transaction_day, transaction_amount, transaction_quantity, discount, customer_id, size, color_code
3750, 2018, 08, 30, 12423.56, 23, 0,2038593, L, Red
3751, 2018, 09, 07, 5356.31, 6, 0.1, 203521, m, orange
3752, 2018, 09, 16, 15.75, 1, 0.22, 5646471, S, blue
3753, 2018, 09, 22, 1251, 7, 0, 3036491, l, Black
3754, 2018, 09, 22, 21484.21, 1356, 75, 049681, xs, Red
3756, 2018, 09, 22, -59.18, 2, 0.333333333333333, 2038593, M, Blue
3757, 2018, 09, 23, 3177.4, 21, .14, 203521, XL, Black
];
结果
Qlik Sense table showing results of the makedate function being used in the load script.
transaction_id |
Transaction Date |
3750 |
30/08/2018 |
3751 |
07/09/2018 |
3752 |
16/09/2018 |
3753 |
22/09/2018 |
3754 |
22/09/2018 |
3756 |
22/09/2018 |
3757 |
23/09/2018 |