Yuvraj,
I am getting "incorrect calculation context" error with all fields belonging to the same query.
I have tried the following:
1. Set the projection function to "none". Removing the Date column doesn't change the grouping. I get multiple with (correct) figures for each date.
2. Changed back the projection function to "sum". Now removing the date column sums up for each KPI, which is incorrect.
Please see the attached screenshot. I can get the right total figures, if I don't include the date field in the query.
The SQL query calculates the totals correctly whether I include or exclude the date field:
(
SELECT
'PP',
Sum(dbo.view_BO_Perf8.DailyRouteTargetPunctuality*dbo.view_BO_Perf8.CntPunc)/Sum(dbo.view_BO_Perf8.CntPunc) target,
100*Sum(dbo.view_BO_Perf8.FndPunc)/Sum(dbo.view_BO_Perf8.CntPunc) actual
FROM
dbo.view_BO_Perf8
WHERE
( dbo.view_BO_Perf8.ParentRoute <> 'City Shuttle' )
AND ( dbo.view_BO_Perf8.ParentRoute <> 'City Shuttle' )
AND
(
rtrim(convert(char,dbo.view_BO_Perf8.Date,111)) >= rtrim(convert(char,dateadd(d, -6, dateadd(d, 6, DATEADD(wk, DATEDIFF(wk,0, getdate() ), -7))) ,111))
AND
rtrim(convert(char,dbo.view_BO_Perf8.Date,111)) <= rtrim(convert(char,dateadd(d, 6, DATEADD(wk, DATEDIFF(wk,0, getdate() ), -7)) ,111))
AND
dbo.view_BO_Perf8.ParentRoute <> 'City Shuttle'
)
UNION
SELECT
'SD',
Sum(dbo.view_BO_Perf8.DailyRouteTargetServiceDelivery*dbo.view_BO_Perf8.SchTrips)/Sum(dbo.view_BO_Perf8.SchTrips),
100*(Sum(dbo.view_BO_Perf8.ActTrips)-0.125*Sum(dbo.view_BO_Perf8.FailShorts))/Sum(dbo.view_BO_Perf8.SchTrips)
FROM
dbo.view_BO_Perf8
WHERE
(
rtrim(convert(char,dbo.view_BO_Perf8.Date,111)) >= rtrim(convert(char,dateadd(d, -6, dateadd(d, 6, DATEADD(wk, DATEDIFF(wk,0, getdate() ), -7))) ,111))
AND
rtrim(convert(char,dbo.view_BO_Perf8.Date,111)) <= rtrim(convert(char,dateadd(d, 6, DATEADD(wk, DATEDIFF(wk,0, getdate() ), -7)) ,111))
)
)
Result:
(No column name) | target | actual |
PP | 82.1618055832943 | 81.8121296851075 |
SD | 99.1184200099033 | 98.3624318968773 |
I need to achieve the same result as the top right table. If it was just one period I would just exclude the date field from the query but I want' to include multiple periods in the same BO table. I wonder why I'm getting the context error.
Do you need more info?