Crystal reports group data by floating hours
It worked like this:
Created new operator "minutes" (number).
Created new formula "floating_hour":
if minute({TableName.RASP_DATE}) < {?minutes} then
time(hour({TableName.RASP_DATE})-1,{?minutes},0) else
if minute({TableName.RASP_DATE}) >= {?minutes} then
time(hour({TableName.RASP_DATE}),{?minutes},0)Created a group by "RASP_DATE" (Order by weeks)
Created a group by "floating_hour" formula.
Summarized RACE_HOURS in the "floating_hours" group.
Group Summary Involving dividing in Crystal Reports
I've done something similar but not using Percentages. The way I thought it out is almost painful to do, but you will have drilldown capabilities. I'll post what I've come up with but if someone can modify this to make it easier, by all means.
First, create the 8 groups you want use and hide them. You will need 14 formulas to create columns for your periods. For your first period, the formula (and following periods) should look like this:
IF {table.period} = "01-2012" THEN
IF DrillDownGroupLevel = 0 THEN
SUM({table.sales}, {table.group1}) / SUM({table.goal}, {table.group1})
ELSE IF DrillDownGroupLevel = 1 THEN
SUM({table.sales}, {table.group2}) / SUM({table.goal}, {table.group2})
ELSE IF DrillDownGroupLevel = 2 THEN
SUM({table.sales}, {table.group3}) / SUM({table.goal}, {table.group3})
ELSE IF DrillDownGroupLevel = 3 THEN
SUM({table.sales}, {table.group4}) / SUM({table.goal}, {table.group4})
...
ELSE
SUM({table.sales}, {table.group8}) / SUM({table.goal}, {table.group8})
ELSE
0
What this formula does is identify what period it is, then determine what group level it is on. It then Sums up the Sales and Goal considering what the group is suppose to be on that level.
- For line IF {table.period} = "01-2012" THEN, I'd set up as a parameter so it will work for multiple years.
- I would rather use a function to determine what group level I was on, but all I know is DrillDownGroupLevel. It is useful but flawed if you try to do something fancy with the groups (conditional surpression) don't do a simple drilldown.
- Change {table.group1} to what ever field you used for that group level. i.e. {table.company}
A drawback on this formula is every time you drill down, the DrillDownGroupLevel will change. The new level you reveal will be correct, but previous levels that still show will change.
Hope this helps.
Related Topics
How to Replace Null Values with a Text
How to Migrate Datetime Values to Datetimeoffset in SQL Server
Swap Values for Two Rows in the Same Table in SQL Server
How to Get Time Part from SQL Server 2005 Datetime in 'Hh:Mm Tt' Format
How to List the Source Table Name of Columns in a View (SQL Server 2005)
Table Valued Function Where Did My Query Plan Go
Multiple SQL Update Statements in Single Query
Using Different Order by with Union
Connect by or Hierarchical Queries in Rdbms Other Than Oracle
Oracle Dynamic Desc and Asc in Order By
Reseed Identity Column in SQL Compact
Postgresql Update Multiple Tables in Single Query
What Determines the Locking Order for a Multi-Table Query
Find the Length of the Longest Row in a Column in Oracle