on 2012 Jun 03 12:06 PM
Hey all,
I'm tryng to do an avarage on sales table.
The table is designed that I have months on the top (column) jan, feb... dec
and rows are devided by years
2010
2011
2012
I need to do an avarage for each year.
and for 2012 I counted the number of the month month(CurrentDate())
and will devide by it.
I have a problem using GridLabelAt when I'm trying to read lable '2012' from my table
I can't find the correct systax for it, this is my code:
if GridLabelAt(year({Sap_Crystal_Logistic;1.DocDate})=2012) then
(
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Jan"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Feb"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Mar"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Apr"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("May"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Jun"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Jul"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Aug"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Sep"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Oct"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Nov"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Dec"), CurrentSummaryIndex)
)
else 99999
Help me correct it please..
Also if you have a better method I would like to hear it.
Thanks
Hi,
For the Yearly average -- Right click the first row in the 'Total' column (by default, this is the left-most column), select 'Edit Summary', and choose 'Average' from the 'Calculate this summary' combo-box. This assumes that the cross-tab always includes 12 months of data, which can be easily done by setting an appropriate record-selection formula.
If you have Crystal Reports 2008, you can add a calculated column.
Here are the steps:
GridValueAt (CurrentRowIndex, CurrentColumnIndex-1, CurrentSummaryIndex)+ GridValueAt(CurrentrowIndex,CurrentColumnIndex-2,CurrentSummaryIndex)
Edit the formula as per your need.
Here is the link on how to create a calculated member column.
http://www.crystalkeen.com/articles/crystalreports/crosstabcalcmember.htm
Let me know if you need more details.
Thanks,
Jothi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey,
Thank you for the reply,
but I have a different issue where I have lines that I need to divide in the current month count.
Example:
2010 will be divided by 12 months
2011 will be divided by 12 months
Current year (2012) will be divided by 6 months because we are in June.
How can I do that formula?
In SQL I can do that:
(CASE when YEAR(T0.DocDate) = YEAR(GETDATE()) Then Month(GETDATE())
else '12'
END) AS 'CurDate',
Quantity/(CASE when YEAR(T0.DocDate) = YEAR(GETDATE()) Then Month(GETDATE())
else '12'
END) AS 'Avarage'
I can't do it in Crystal..
Can you advise?
Hello Heli,
If you are using a crosstab and the rows are based on the month number the crosstab average summary is smart enough not to take into account the months that do not have a value. So if for 2012 there is only data til June then it will automatically average only the 6 months.
Can you confirm that it is or is not doing this? Are there actual 0 values for July to December in your database?
If there are then you can filter those out in the record selection with something like {datefield} <= currrentdate.
Regards,
Graham
year / month | jan | feb | mar | apr... | total | avg |
---|---|---|---|---|---|---|
2010 | 12 | 10 | 5 | 10 | 37 | sum/12 (months) |
2011 | 12 | 10 | 5 | 10 | 37 | sum/12 (months) |
2012 | 10 | 10 | 0 | 0 | 20 | sum/6(current months count) |
This is my table, imagine there is 12 moths their, every year the average divided by 12 months,
and current year divided by 6 because we are in June..
Cross tab average does not ignore the zeros and divides 2012 in 12 instead of 6.
How can I tell it to look at the years and if the year = (current year)
Then divide it by the months count (6)
Thanks
Hi Heli,
Try this as the Calculation Formula for the Calculated Member:
if Gridlabelat("Sheet1_.Year",1) = 2012 then
(
(GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Jan"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Feb"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Mar"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Apr"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("May"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Jun"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Jul"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Aug"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Sep"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Oct"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Nov"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Dec"), CurrentSummaryIndex))/month(currentdate)
)
else
(GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Jan"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Feb"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Mar"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Apr"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("May"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Jun"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Jul"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Aug"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Sep"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Oct"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Nov"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Dec"), CurrentSummaryIndex) )/12
Let me know how this goes!
-Abhilash
Hey,
I did this:
**************************************
@CurDate = year(CurrentDate)
@X = month(currentdate)
************************************
if
year(Gridlabelat("TOD_Master_sheet_For_Sap_Crystal_Logistic;1.DocDate",1)) = ({@CurDate})
then
(
(GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Jan"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Feb"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Mar"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Apr"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("May"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Jun"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Jul"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Aug"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Sep"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Oct"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Nov"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Dec"), CurrentSummaryIndex)) /({@X})
)
else
99999
But now it divides everything by the current month (X).
Thanks
Heli
Hi Heli,
Try this:
If year(Gridlabelat("TOD_Master_sheet_For_Sap_Crystal_Logistic;1.DocDate",1)) = ({@CurDate}) then
(
(GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Jan"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Feb"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Mar"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Apr"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("May"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Jun"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Jul"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Aug"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Sep"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Oct"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Nov"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Dec"), CurrentSummaryIndex))/({@X})
)
else
(GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Jan"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Feb"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Mar"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Apr"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("May"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Jun"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Jul"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Aug"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Sep"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Oct"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Nov"), CurrentSummaryIndex)+
GridValueAt(CurrentRowIndex, GetColumnPathIndexOf("Dec"), CurrentSummaryIndex) )/12
Let me know how this goes!
-Abhilash
Hi Heli,
It doesn't matter as long as it's a number.
So, 2,012.00 is same as 2012.
Anyway, I think I see what's going wrong here. The Gridlabelat() function you're using is only looking at the first row when it should actually evaluate for each row.
Change the first line in the code to:
If year(Gridlabelat("TOD_Master_sheet_For_Sap_Crystal_Logistic;1.DocDate",currentrowindex)) = year(currentdate) then
(
)
else
(
)
I added currentrowindex to the formula.
Let me know how this goes!
-Abhilash
User | Count |
---|---|
67 | |
8 | |
8 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.