Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Return the index position from an array Post Reply Post New Topic
Author Message
Robotacha
Groupie
Groupie
Avatar

Joined: 11 Nov 2009
Location: United Kingdom
Online Status: Offline
Posts: 97
Quote Robotacha Replybullet Topic: Return the index position from an array
     Posted: 26 Oct 2011 at 1:08pm
Hello,
 
this formula finds the best sales month from the last 12 months:
 
Dim MonthArray () as number
MonthArray = Array({CUSTHIS.SALEQTY00}, {CUSTHIS.SALEQTY01}, {CUSTHIS.SALEQTY02}, {CUSTHIS.SALEQTY03}, {CUSTHIS.SALEQTY04}, {CUSTHIS.SALEQTY05}, _
{CUSTHIS.SALEQTY06}, {CUSTHIS.SALEQTY07}, {CUSTHIS.SALEQTY08}, {CUSTHIS.SALEQTY09}, {CUSTHIS.SALEQTY10}, {CUSTHIS.SALEQTY11}, {CUSTHIS.SALEQTY12})
formula = maximum(MonthArray)
 
It returns the value: 302 ,  which is {CUSTHIS.SALEQTY11}
 
{CUSTHIS.SALEQTY11} is position 12 of 13 in the array.
 
 
What formula would I write to return this position?
 
 
the reason I want to do this,
SALEQTY00 is the current month (October),  SALEQTY01 is last month (September),  SALEQTY02 is last month -1 (August) and so on....
 
I need to identify which month it is and display that as the monthname in the report.

once I can identify the index of the best month, I can simply write a formula like:
 
IF {@bestmonthindex}=1 THEN monthname(month(currentdate) ELSE
IF {@bestmonthindex}=2 THEN monthname(month)currentdate)-1) ELSE
 
etc...
 
 
 
Can anyone advise on the best way for me to achieve this?
 
Please?
 
 
Thanks.
 
Mike
 


 
Regards,

Michael Jones
IP IP Logged
SamD
Newbie
Newbie


Joined: 24 Oct 2011
Online Status: Offline
Posts: 15
Quote SamD Replybullet Posted: 27 Oct 2011 at 3:07am
Michael,
Have you look at the Group Sort Expert that will find the top sales.
IP IP Logged
Robotacha
Groupie
Groupie
Avatar

Joined: 11 Nov 2009
Location: United Kingdom
Online Status: Offline
Posts: 97
Quote Robotacha Replybullet Posted: 27 Oct 2011 at 3:14am
yes, not really what I was after.
 
the reason I am identifying the best month, is, I am building a decline account report.
 
so, I identify the best month, then comapre that against the current month or last full month, then I will sort the customers in descending order based on the difference.
 
I have managed to sort this though using a big formula like:
 
IF {@BESTMONTHCHECK}={CUSTHISQTY00} THEN {@month0}&" "&{@year0} ELSE
IF {@BESTMONTHCHECK}={CUSTHISQTY01} THEN {@month1}&" "&{@year1} ELSE
IF {@BESTMONTHCHECK}={CUSTHISQTY02} THEN {@month2}&" "&{@year2} ELSE  etc etc...
 
 
I simply wrote 12x @month & 12x @year formulas,
 
and my formula now displays the correct date that matches the CUSTHISQTY field :)
 


Edited by Robotacha - 27 Oct 2011 at 3:15am
Regards,

Michael Jones
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 27 Oct 2011 at 4:04am
why not do something like:
local numbervar x := {@bestmonthindex};
monthname(month)currentdate)-(x -1);
 
or you could create an array of month names in the order that is needed and then just access the value in the correct array location.
 
Hopefully one of these will help
 
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum