Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 2720

Re: Weekly and YTD figures

$
0
0

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.

 

KPI's with and without dates.png

 

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)targetactual
PP82.161805583294381.8121296851075
SD99.118420009903398.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?


Viewing all articles
Browse latest Browse all 2720

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>