Qlikview - 脚本中的总和

时间:2016-09-01 12:42:19

标签: qlikview

我有脚本

LOAD * INLINE [
 Document, Date, Itam, Line, Saldo, Unit
 Doc1, 12.12.2015, Item1, 1, 10, m
 Doc1, 3.04.2015, Item2, 2, 15, kg
 Doc2, 11.09.2015, Item1, 1, 6, kg
 Doc3, 11.04.2015, Item1, 1, 13, m
 Doc3, 21.03.2015, Item5, 2, 45, l
 Doc4, 20.04.2016, Item4, 1, 7, l
 Doc5, 12.01.2016, Item1, 1, 13, kg
 Doc6, 7.09.2016, Item3, 1, 16, m
 Doc6, 21.09.2016, Item3, 2, 21, kg
 Doc7, 1.01.2016, Item2, 1, 3, l
];

我想用脚本逐年得到萨尔多的总和。如何修改脚本以获得如下内容:

Load
Year2015,
SumOfSaldo2015,
Year2016,
SumOfSaldo2016

当我在文本框中调用SumOfSaldo2015以获得2015年saldo的总和时

1 个答案:

答案 0 :(得分:1)

当你应该能够通过在QlikView中使用尺寸来实现它时,这似乎有些奇怪 - 只需根据日期创建一年尺寸......

LOAD *,
 right(Date,4) as Year;
LOAD * INLINE [
 Document, Date, Itam, Line, Saldo, Unit
 Doc1, 12.12.2015, Item1, 1, 10, m
 Doc1, 3.04.2015, Item2, 2, 15, kg
 Doc2, 11.09.2015, Item1, 1, 6, kg
 Doc3, 11.04.2015, Item1, 1, 13, m
 Doc3, 21.03.2015, Item5, 2, 45, l
 Doc4, 20.04.2016, Item4, 1, 7, l
 Doc5, 12.01.2016, Item1, 1, 13, kg
 Doc6, 7.09.2016, Item3, 1, 16, m
 Doc6, 21.09.2016, Item3, 2, 21, kg
 Doc7, 1.01.2016, Item2, 1, 3, l
];

或者,如果你只是一个统一的观点......

Temp:
LOAD *,
 right(Date,4) as Year;
LOAD * INLINE [
 Document, Date, Itam, Line, Saldo, Unit
 Doc1, 12.12.2015, Item1, 1, 10, m
 Doc1, 3.04.2015, Item2, 2, 15, kg
 Doc2, 11.09.2015, Item1, 1, 6, kg
 Doc3, 11.04.2015, Item1, 1, 13, m
 Doc3, 21.03.2015, Item5, 2, 45, l
 Doc4, 20.04.2016, Item4, 1, 7, l
 Doc5, 12.01.2016, Item1, 1, 13, kg
 Doc6, 7.09.2016, Item3, 1, 16, m
 Doc6, 21.09.2016, Item3, 2, 21, kg
 Doc7, 1.01.2016, Item2, 1, 3, l
];

Saldo:
LOAD 
 Year AS Year,
 sum(Saldo) as SumOfSaldo
RESIDENT TEMP
GROUP BY Year;

但是,如果你真的需要这样做,你可以做点像......

Temp:
LOAD *,
 right(Date,4) as Year;
LOAD * INLINE [
 Document, Date, Itam, Line, Saldo, Unit
 Doc1, 12.12.2015, Item1, 1, 10, m
 Doc1, 3.04.2015, Item2, 2, 15, kg
 Doc2, 11.09.2015, Item1, 1, 6, kg
 Doc3, 11.04.2015, Item1, 1, 13, m
 Doc3, 21.03.2015, Item5, 2, 45, l
 Doc4, 20.04.2016, Item4, 1, 7, l
 Doc5, 12.01.2016, Item1, 1, 13, kg
 Doc6, 7.09.2016, Item3, 1, 16, m
 Doc6, 21.09.2016, Item3, 2, 21, kg
 Doc7, 1.01.2016, Item2, 1, 3, l
];

Saldo:
LOAD 
 Year AS Year2015,
 sum(Saldo) as SumOfSaldo2015
RESIDENT TEMP
GROUP BY Year
WHERE Year = 2015;

CONCATENATE(Saldo)
LOAD 
 Year AS Year2016,
 sum(Saldo) as SumOfSaldo2016
RESIDENT TEMP
GROUP BY Year
WHERE Year = 2016;

DROP TABLE Temp;