将一个qlikview(qvd)文件拆分为两个qvd文件

时间:2016-01-06 08:37:23

标签: split concatenation qlikview

我的qvd文件包含两年的数据。我必须将这些数据分成两个qvd文件,一个属于当前年份,另一个属于明年或去年。我尝试过使用时间分析。但是现在我丢失了要使用的代码。有什么想法或帮助吗?提前谢谢。

变量字段的屏幕截图:

Date Data screenshot

YearsToLoad:
Load
    left(BATCH_NO, 4) as BATCH_NO
;
Load
    distinct BATCH_NO
From 
    Current.qvd (qvd)
;   

for i = 1 to FieldValueCount('BATCH_NO')
    let vYear = FieldValue('BATCH_NO', $(i));

    Years:
    Load
        $(vYear)    as BATCH_NO
    AutoGenerate(1)
    ;

    Current:
    Load
        BATCH_NO
    From
        Current.qvd (qvd)   
    Where
        left(BATCH_NO, 4) = $(vYear)
    ;

    Store  Current into RawDataLoad_$(vYear).qvd;
    Drop Tables Years, Current;

next

    Drop Table YearsToLoad;

当我对数字进行硬编码时,我的脚本是这样的:

[Last]:
NoConcatenate
load *
Resident CurrentData
where BATCH_NO >= 20150101 AND BATCH_NO < 20160101 ;

[Current]:
NoConcatenate
load *
Resident CurrentData
where BATCH_NO >= 20160101 AND BATCH_NO < 20170101 ;

STORE Current into Current.qvd(qvd);
STORE Last into Last.qvd(qvd);

然后这是我为“Last.qvd”获取的qvd文件

1 个答案:

答案 0 :(得分:1)

下面的脚本将从主qvd加载不同的年份,循环显示值并为每年生成qvd。 第一个(注释)部分是我在本例中使用的示例数据。

//RawData:
//Load * Inline [
//  Value, Year
//  1    , 2013
//  2    , 2013
//  3    , 2014
//  4    , 2014
//  5    , 2014
//  6    , 2015
//  7    , 2015
//  8    , 2015
//  9    , 2016
//  10   , 2016
//];
//
//Store RawData into RawData.qvd;

// Load the distinct Year values from the main qvd
YearsToLoad:
Load
    distinct Year as YearToLoad
From 
    RawData.qvd (qvd)
;   

// Start looping through the distinct values
for i = 1 to FieldValueCount('YearToLoad')
    let vYear = FieldValue('YearToLoad', $(i));

    // Load the current iteration value
    // The resulted field name must match the field name from the next 
    // load. This way will keep the qvd optimized load
    Years:
    Load
        $(vYear)    as Year
    AutoGenerate(1)
    ;

    RawDataLoad:
    Load
        Value,
        Year
    From
        RawData.qvd (qvd)   
    Where
        Exists(Year) // this is the important bit that will filter the qvd
    ;

    // Store the filtered qvd
    Store RawDataLoad into RawDataLoad_$(vYear).qvd;
    // Drop the temp tables
    Drop Tables Years, RawDataLoad;

next

// Drop the table that loaded the distinct Year values
Drop Table YearsToLoad;

更新

如果没有包含年份值的专用字段且只有日期字段(在这种情况下格式为YYYYMMDD),则可以使用以下脚本。由于qvd优化的负载将被破坏,因此速度会变慢。

//RawData:
//Load * Inline [
//  Value, Date
//  1    , 20130102
//  2    , 20130103
//  3    , 20140101
//  4    , 20140102
//  5    , 20140103
//  6    , 20150101
//  7    , 20150102
//  8    , 20150103
//  9    , 20160104
//  10   , 20160105
//];
//
//Store RawData into RawData.qvd;
//
//exit Script;

YearsToLoad:
Load
    left(Date, 4) as YearToLoad
;
Load
    distinct Date
From 
    RawData.qvd (qvd)
;   

for i = 1 to FieldValueCount('YearToLoad')
    let vYear = FieldValue('YearToLoad', $(i));

    RawDataLoad:
    Load
        Value,
        Date
    From
        RawData.qvd (qvd)   
    Where
        left(Date, 4) = $(vYear)
    ;

    Store RawDataLoad into RawDataLoad_$(vYear).qvd;
    Drop Table RawDataLoad;

next

Drop Table YearsToLoad;