私はSQLでこれをやっていると思います。ここで私はそれを行うだろうかの例の下にあります:
declare @tbl table
(
Country varchar(2),
Type varchar(1),
Names varchar(5),
Qty int,
DateValue datetime
)
insert into @tbl
values ('US', 'A','BB-1',10,'12/01/2015'),
('US', 'A','BB-2',20,'12/01/2015'),
('IN', 'A','BB-1',0,'12/01/2015'),
('IN', 'A','BB-2',10,'12/01/2015'),
('US', 'A','BB-1',30,'12/01/2016'),
('US', 'A','BB-2',40,'12/01/2016'),
('IN', 'A','BB-1',50,'12/01/2016'),
('IN', 'A','BB-2',70,'12/01/2016')
select
t.*,
YearEnd.YearEnd ,
case when YearEnd.YearEnd = 0 then null else (t.Qty - YearEnd.YearEnd)/convert(decimal(36,4),YearEnd.YearEnd) end as YearEndCalc
from @tbl as t
left join
(
select
year(DateValue) as YearValue,
Type,
sum(Qty) as YearEnd
from @tbl
where
month(DateValue) = 12
group by
year(DateValue) ,
Type
) as YearEnd
on YearEnd.YearValue = year(t.datevalue)-1
and YearEnd.Type = t.Type
私はまだあなたが探しているまさにワークアウトが、それらは括弧(H13 - G13)必要があるように、それはあなたのYTD式を言及する価値が見えると思っています/ G13を..私は%変化を探していると思います。今書いているとおり、(H13-G13/G13)あなたはH13-1になります。 – Jesse
はい、その割合です。それを修正していただきありがとうございます。 – Papil
お願いします。 – Papil