Hello,
I am using a dynamic crosstab report to track performance statistics for my company and I have hit a problem.
I would like the option to track stats daily (for the last 7 complete days), weekly (for the last 6 weeks) and monthly (for the last 6 complete months).
Daily and monthly are not causing me a problem - I have used the following code to construct the query:
And the following to create the "strPivot" string:
Daily:
Monthly:
I am now stuck with how to create the pivot for a dynamic weekly range. Ideally I would like the user to select an end date (any date up to and including yesterday) and the report would give a total for each of the last 6 weeks - preferably the week could run from any day, but if I have to use Mon-Sun that would also be acceptable. Can anyone help me with this? I've googled like there's no tomorrow and I'm not having any luck!
I can supply any more information/code if required.
Many thanks,
Olly
I am using a dynamic crosstab report to track performance statistics for my company and I have hit a problem.
I would like the option to track stats daily (for the last 7 complete days), weekly (for the last 6 weeks) and monthly (for the last 6 complete months).
Daily and monthly are not causing me a problem - I have used the following code to construct the query:
Code:
strXT = "TRANSFORM Sum(Query2.STAT) AS SumOfSTAT " & _ "SELECT Query2.Site, Query2.OM, Query2.TM, Query2.Name " & _ "FROM Query2 " & _ "GROUP BY Query2.Site, Query2.OM, Query2.TM, Query2.Name " & _ strPivot & ";"
Daily:
Code:
strPivot = "PIVOT [DATE]"
Code:
If Format(strStopDate, "MMM") = "Jan" Then strPivot = "PIVOT Format([DATE],""MMM"") IN (""Aug"", ""Sep"", ""Oct"", ""Nov"", ""Dec"", ""Jan"")" End If If Format(strStopDate, "MMM") = "Feb" Then strPivot = "PIVOT Format([DATE],""MMM"") IN (""Sep"", ""Oct"", ""Nov"", ""Dec"", ""Jan"", ""Feb"")" End If If Format(strStopDate, "MMM") = "Mar" Then strPivot = "PIVOT Format([DATE],""MMM"") IN (""Oct"", ""Nov"", ""Dec"", ""Jan"", ""Feb"", ""Mar"")" End If If Format(strStopDate, "MMM") = "Apr" Then strPivot = "PIVOT Format([DATE],""MMM"") IN (""Nov"", ""Dec"", ""Jan"", ""Feb"", ""Mar"", ""Apr"")" End If If Format(strStopDate, "MMM") = "May" Then strPivot = "PIVOT Format([DATE],""MMM"") IN (""Dec"", ""Jan"", ""Feb"", ""Mar"", ""Apr"", ""May"")" End If If Format(strStopDate, "MMM") = "Jun" Then strPivot = "PIVOT Format([DATE],""MMM"") IN (""Jan"", ""Feb"", ""Mar"", ""Apr"", ""May"", ""Jun"")" End If If Format(strStopDate, "MMM") = "Jul" Then strPivot = "PIVOT Format([DATE],""MMM"") IN (""Feb"", ""Mar"", ""Apr"", ""May"", ""Jun"", ""Jul"")" End If If Format(strStopDate, "MMM") = "Aug" Then strPivot = "PIVOT Format([DATE],""MMM"") IN (""Mar"", ""Apr"", ""May"", ""Jun"", ""Jul"", ""Aug"")" End If If Format(strStopDate, "MMM") = "Sep" Then strPivot = "PIVOT Format([DATE],""MMM"") IN (""Apr"", ""May"", ""Jun"", ""Jul"", ""Aug"", ""Sep"")" End If If Format(strStopDate, "MMM") = "Oct" Then strPivot = "PIVOT Format([DATE],""MMM"") IN (""May"", ""Jun"", ""Jul"", ""Aug"", ""Sep"", ""Oct"")" End If If Format(strStopDate, "MMM") = "Nov" Then strPivot = "PIVOT Format([DATE],""MMM"") IN (""Jun"", ""Jul"", ""Aug"", ""Sep"", ""Oct"", ""Nov"")" End If If Format(strStopDate, "MMM") = "Dec" Then strPivot = "PIVOT Format([DATE],""MMM"") IN (""Jul"", ""Aug"", ""Sep"", ""Oct"", ""Nov"", ""Dec"")" End If
I can supply any more information/code if required.
Many thanks,
Olly
Comment