脚本示例
在本例中,首次加载数据时不使用 AutoNumber 语句。然后添加 AutoNumber 语句以显示效果。
示例中所使用的数据:
将以下数据作为数据加载编辑中的内联加载载入,以创建以下脚本示例。将 AutoNumber 语句注释掉。
RegionSales:
LOAD *,
Region &'|'& Year &'|'& Month as KeyToOtherTable
INLINE
[ Region, Year, Month, Sales
North, 2014, May, 245
North, 2014, May, 347
North, 2014, June, 127
South, 2014, June, 645
South, 2013, May, 367
South, 2013, May, 221
];
Budget:
LOAD Budget,
Region &'|'& Year &'|'& Month as KeyToOtherTable
INLINE
[Region, Year, Month, Budget
North, 2014, May, 200
North, 2014, May, 350
North, 2014, June, 150
South, 2014, June, 500
South, 2013, May, 300
South, 2013, May, 200
];
//AutoNumber KeyToOtherTable;
有关使用内联加载的详细信息,请参见内联加载。
创建可视化
在 Qlik Sense 工作表中创建两个表格可视化。将 KeyToOtherTable、Region、Year、Month 和 Sales 作为维度添加到第一个表格。将 KeyToOtherTable、Region、Year、Month 和 Budget 作为维度添加到第二个表格。
结果
RegionSales 表格
KeyToOtherTable |
Region |
Year |
Month |
Sales |
North|2014|June |
North |
2014 |
June |
127 |
North|2014|May | North | 2014 | May | 245 |
North|2014|May | North | 2014 | May | 347 |
South|2013|May | South | 2013 | May | 221 |
South|2013|May | South | 2013 | May | 367 |
South|2014|June | South | 2014 | June | 645 |
预算表格
KeyToOtherTable |
Region |
Year |
Month |
Budget |
North|2014|June |
North |
2014 |
June |
150 |
North|2014|May | North | 2014 | May | 200 |
North|2014|May | North | 2014 | May | 350 |
South|2013|May | South | 2013 | May | 200 |
South|2013|May | South | 2013 | May | 300 |
South|2014|June | South | 2014 | June | 500 |
解释
该示例显示了链接两个表的复合字段 KeyToOtherTable。未使用 AutoNumber。请注意 KeyToOtherTable 值的长度。
添加 AutoNumber 语句
取消对加载脚本中的 AutoNumber 语句的注释:
AutoNumber KeyToOtherTable;
结果
RegionSales 表格
KeyToOtherTable |
Region |
Year |
Month |
Sales |
1 |
North |
2014 |
June |
127 |
1 | North | 2014 | May | 245 |
2 | North | 2014 | May | 347 |
3 | South | 2013 | May | 221 |
4 | South | 2013 | May | 367 |
4 | South | 2014 | June | 645 |
预算表格
KeyToOtherTable |
Region |
Year |
Month |
Budget |
1 |
North |
2014 |
June |
150 |
1 | North | 2014 | May | 200 |
2 | North | 2014 | May | 350 |
3 | South | 2013 | May | 200 |
4 | South | 2013 | May | 300 |
4 | South | 2014 | June | 500 |
解释
KeyToOtherTable 字段值已替换为唯一的整数值,因此,字段值的长度已减小,从而节省内存。两个表中的键字段都受 AutoNumber 的影响,并且表保持链接。尽管此例主要用于演示目的,但对于包含大量行的表格将非常有意义。