I'm trying to get the cyq calculation to work in the following query but it keeps returning null:

select name,value,date_collected,

case month(date_collected) when 1 then 1 when 2 then 1 when 3 then 1

when 4 then 2 when 5 then 2 when 6 then 2

when 7 then 3 when 8 then 3 when 9 then 3

when 10 then 4 when 11 then 4 when 12 then 4

end as calquarter,

year(date_collected) as calyear,

(calyear*10+calquarter) as cyq

from fact_data

join metrics on fact_data.metric_id=metrics.id

where entity_id=1 and metric_id=1

order by name

I believe you will need to use the following to get the value you desire.

select name,value,date_collected,

case month(date_collected) when 1 then 1 when 2 then 1 when 3 then 1

when 4 then 2 when 5 then 2 when 6 then 2

when 7 then 3 when 8 then 3 when 9 then 3

when 10 then 4 when 11 then 4 when 12 then 4

end as calquarter,

year(date_collected) as calyear,

((year(date_collected))*10

from fact_data

join metrics on fact_data.metric_id=metric

where entity_id=1 and metric_id=1

order by name