Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Need help with a formula Post Reply Post New Topic
Author Message
Lil Dot
Newbie
Newbie


Joined: 12 Oct 2009
Online Status: Offline
Posts: 3
Quote Lil Dot Replybullet Topic: Need help with a formula
     Posted: 12 Oct 2009 at 3:48pm

For my report I would like to have crystal pull up the previous months sales data.  So for example if this month is October 2009, then I would want September 2009 sales.

 

But I've come across a problem that I need help with, let's say that the current month is January 2010, then I would want Sales data for December of 2009.  I don’t know of a formula since I would be pulling data from the previous year.

 

So if here is my basic formula that I have.  (I need help with the first line).

 

If Month (CurrentDate)=1 then (Need help here);

If Month (CurrentDate)=2 then {IM9_ItemSalesDetailWhse.QtySoldPeriod1};

If Month (CurrentDate)=3 then {IM9_ItemSalesDetailWhse.QtySoldPeriod2};

If Month (CurrentDate)=4 then {IM9_ItemSalesDetailWhse.QtySoldPeriod3};

If Month (CurrentDate)=5 then {IM9_ItemSalesDetailWhse.QtySoldPeriod4};

If Month (CurrentDate)=6 then {IM9_ItemSalesDetailWhse.QtySoldPeriod5};

If Month (CurrentDate)=7 then {IM9_ItemSalesDetailWhse.QtySoldPeriod6};

If Month (CurrentDate)=8 then {IM9_ItemSalesDetailWhse.QtySoldPeriod7};

If Month (CurrentDate)=9 then {IM9_ItemSalesDetailWhse.QtySoldPeriod8};

If Month (CurrentDate)=10 then {IM9_ItemSalesDetailWhse.QtySoldPeriod9};

If Month (CurrentDate)=11 then {IM9_ItemSalesDetailWhse.QtySoldPeriod10};

If Month (CurrentDate)=12 then {IM9_ItemSalesDetailWhse.QtySoldPeriod11}

else 0

 

  

Thanks to anyone who can help, I appreciate it.  Smile



Edited by Lil Dot - 12 Oct 2009 at 3:49pm
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 12 Oct 2009 at 4:05pm

this depends on how your data is stored. Your other formula items do not indicate what year either so this may not just be an issue for Jan.

Where is the year store in the DB or do you have a different table per year? is there a date fiel per row that you can key off of instead of the period value?
{table.field} in lastfullmonth
IP IP Logged
Lil Dot
Newbie
Newbie


Joined: 12 Oct 2009
Online Status: Offline
Posts: 3
Quote Lil Dot Replybullet Posted: 12 Oct 2009 at 8:53pm
Hi DBlank,
I've selected the current year by the select expert option.  So I believe that is in a different table.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 13 Oct 2009 at 7:47am
I am going to guess that there is another field in the this same table (IM9_ItemSalesDetailWhse) that identifies the year so that you have one row of sales data in the table for the entire year.
Your select statement would have to account for this to determine which data row to select. How to write that depends on how that year field is stored but it could be something like:
if month(currentdate)=1 then Year(dateadd('y',-1,currentdate))={table.YearField} else
Year(currentdate)={table.YearField}
 
Is this on track here?


Edited by DBlank - 13 Oct 2009 at 7:48am
IP IP Logged
Lil Dot
Newbie
Newbie


Joined: 12 Oct 2009
Online Status: Offline
Posts: 3
Quote Lil Dot Replybullet Posted: 13 Oct 2009 at 3:51pm
Hi DBlank,
I used the expert and chose for the Date "is in the period" "LastFullMonth"  I didn't even know there was an option for that.  Embarrassed
 
I tested this by changing the date in the report selection to January.  This way works and I am satisfied with the results.
 
I thank you so much for taking the time to help me out.  I really appreciate it, you are very kind.  Wink
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