Sunday, March 11, 2012
Crystal Report Group by Formula
I am a novice and any help would be much appreciated.
The database I am using is as below:
A/C No. Name Payments
1 Brown 10.00
1 Brown 25.00
1 Brown 40.00
2 Jones 100.00
2 Jones 150.00
2 Jones 175.00
2 Jones 56.00
3 Smith 65.00
I have grouped the report by account number. I have then created a formula that categorises the customer based on their payments. I then wish to group customers by these categories but Crystal will not allow me to do so.
The best I can do at the moment is export the initial report to Excel and then create a new report in Crystal based on this.
Can anyone point me in the right direction?
Thanks
Andyyou can group by using formula
can u write the formula, so that i can check it.
Sunday, February 19, 2012
Cross Tab Report
Hi,
I need some help on crosstab query. I have tried the examles, but somehow, not able to find a right solution.
Any help will be appreciated. The report I would like to have is the one at the bottom.
thx.
Josh
Table Structure>
How the resultset should look like>
Thursday, February 16, 2012
Cross Tab Query
Hi,
I need some help on crosstab query. I have tried the examles, but somehow, not able to find a right solution.
Any help will be appreciated.
thx.
Josh
Table Structure>
How the resultset should look like>
AvgEarningPerProduct = Revenue * 1.0 / Volume,
Month
from
(
select Brand, Product,
Volume = case when Line = 'Volume' then Jan else 0 end,
Revenue = case when Line = 'Revenue' then Jan else 0 end,
Month = 'Jan'
from yourtable
union all
select Brand, Product,
Volume = case when Line = 'Volume' then Feb else 0 end,
Revenue = case when Line = 'Revenue' then Feb else 0 end,
Month = 'Feb'
from yourtable
union all
select Brand, Product,
Volume = case when Line = 'Volume' then Mar else 0 end,
Revenue = case when Line = 'Revenue' then Mar else 0 end,
Month = 'Mar'
from yourtable
)a|||
Hi Josh,
I'm not clear on having how you'd differentiate the multiple entries (I just added them together and recalculated average earnings):
Code Snippet
SELECT
Brand
, Product
, Volume
, Revenue
, Cast(Revenue*1./Volume As Decimal(5,2)) As AvgEarningPerProduct
, MonthName
FROM (
SELECT
Brand
, Product
, Sum(Case When Line = 'Volume' Then
Case MonthName
When 'jan' Then jan
When 'feb' Then feb
When 'mar' Then mar
When 'total' Then total
End
End
) Volume
, Sum(Case When line = 'Revenue' then
Case MonthName
When 'jan' Then jan
When 'feb' Then feb
When 'mar' Then mar
When 'total' Then total
End
End
) Revenue
, MonthName
, MonthNumber
FROM #data, (
SELECT 1 MonthNumber, 'Jan' MonthName UNION ALL
SELECT 2, 'Feb' UNION ALL
SELECT 3, 'Mar' UNION ALL
SELECT 13, 'Total') MonthData
GROUP BY Brand, Product, MonthName, MonthNumber
) Data
ORDER BY Brand, Product, MonthNumber;
Jamie
|||Hi Tan,
Thanks for your help. The query now works perfect. The downside is performance. As I have 20 columns as the one i mentioned in example (Volume, Revenue etc.) and 12 months, it takes some time ro return the results.
BTW, there is aone small problem. Now when I pull the data in reports the month get sorted alphabeticall i.e. April onwards.
Any suggestion, how I can change that?
thanks a lot for your help
Regards
Josh
|||Josh,
"BTW, there is aone small problem. Now when I pull the data in reports the month get sorted alphabeticall i.e. April onwards.
Any suggestion, how I can change that?"
Yes, create a table that has your Month abbreviations, and a SMALLINT or CHAR(1) sort_key to associate with each month. Include such a table in your JOINs to provide the desired sort order.
Dan