Hi all. I have a difficult problem whereby the data I have is on weeks and I need to produce monthly reports. I first thought is to calculate the number of days the week has in a particular month. So 7 days we don't have a problem, all totals are added in full. But at the end of the month the week may only have 3 days in the month. So maybe I need to then have 3/7 of the week total in the previous month and 4/7 in the next. If so then I will try and work out. I just wondered if there was any other clever way. Thanks in advance Scott
Create a calendar table with days in it. Have a column for the week and another for the month. Then you can agggregate using the month and week and also count the number of days in each week for the month.
It would be better if you converted the underlying data to be by day then you can report by week and month easily using that table.
========================================== Cursors are useful if you don't know sql. SSIS can be used in a similar way. Beer is not cold and it isn't fizzy.
WITH RES AS ( SELECT DISTINCT FD_Year ,FD_Week ,CAST(CAST((SELECT COUNT(CalendarWeek) FROM Calendar WHERE CalendarYear = A.FD_Year AND CalendarWeek = A.FD_Week AND CalendarMonth = 1) as Float) / 7 as Float) as WeekPercent ,[FD_TotalInvoiceSale] FROM [Pies].[dbo].[ForecastData] A ) SELECT FD_Year ,FD_Week ,WeekPercent ,FD_TotalInvoiceSale ,CAST(CAST(FD_TotalInvoiceSale as Float) * CAST(WeekPercent as Float) as Float) FROM RES