Create simplified data range in Crystal Reports

Posted on 2013-05-13
Last Modified: 2013-05-17
Hi Experts,

I need to create 2 month / Year range parameters..Where the results are based on
{GlPeriod to GlPeriod } in {GlYear to GlYear}
{GlPeriod to GlPeriod} in {GlYear to GlYear}

I was hoping to have 1 Paramter for the first range of GlPeriod / GlYear to GlPeriod / GlYear

and another for GlPeriod2 / GlYear2 to GlPeriod2 / GlYear2

my available fields are {GlPeriod} and {GlYear}

I hope this make sense
Question by:Mikeyman_01
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 14

Expert Comment

ID: 39161579
I think there must be a typo in your post, but I will try to help anyway.

You can use between in Crystal record selection.

Even if your GL periods are stored as text, you should still be able to do this.

Create a RANGE parameter that is a text.  "Range" is in the lower part of the parameter set up.  Instruct your users to enter the range is PPYYYY format (periodyear format). Repeat this for your second parameter range so that you have two parameters.

In your report selection your formula would look something like

//concatenates your two single fields into one to compare against parameter.
{table.GLPeriod}&{table.GLYear} in minimum({?Param1}) to maximum({?Param1})
{table.GLPeriod}&{table.GLYear} in minimum({?Param2}) to maximum({?Param2})
LVL 101

Expert Comment

ID: 39161625
You can use the ranges directly

{table.GLPeriod}&{table.GLYear} in {?Param1}  
{table.GLPeriod}&{table.GLYear} in {?Param2}


Author Comment

ID: 39163697
i Have created a Record Selection formula  ({@StartRange1} in {?StartRange1} to {?EndRange1})

@StartRange1 = ToText({ArTrnDetail.GlPeriod},0,"") +  ToText({ArTrnDetail.GlYear},0,"")

My @Sales formula = if {@StartRange1} in {?StartRange1} to {?EndRange1} then  {ArTrnDetail.NetSalesValue}
else 0

If i enter 32013 at {?StartRange1}and 52013 at {?EndRange1} i get all Sales Data from the beginning of time... but when i enter 32013 at both of these prompts i get only 32013 Sales Data.. How can i build this so i get only the Sales information between these
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

LVL 35

Expert Comment

ID: 39164329
I wouldn't expect 32013 to 52013 to give you "all Sales Data from the beginning of time", but it would include period 4 in any year, and period 5 in any year up to 2013 (and period 3 in any year after 2013).  You need to have the year first.

  And assuming that the period numbers go above 9, you also need to include a leading 0 on the period numbers below 10.  Ignoring the year for the moment, a range like period 5 to 11 won't work, because "5" is greater than "11".  It needs to be "05", or " 5" (with a leading space).

 Putting the year first and assuming a 2 digit period with a leading 0, if necessary, you could change @StartRange1 to:

ToText({ArTrnDetail.GlYear},0,"") + ToText({ArTrnDetail.GlPeriod},"00")

 And, of course, you need to rearrange your parameter values to be year then period.  Assuming that they will always be pyyyy (for the periods below 10) or ppyyyy, you could use something like:

Mid (Right ("0" + {?StartRange1}, 6), 3, 4) + Left (Right ("0" + {?StartRange1}, 6), 2)


Author Comment

ID: 39164653
Hi James

How do I work this piece of the formula into my report??

Mid (Right ("0" + {?StartRange1}, 6), 3, 4) + Left (Right ("0" + {?StartRange1}, 6), 2) not sure where to put this
LVL 35

Accepted Solution

James0628 earned 500 total points
ID: 39167519
Sorry.  I was kind of in a hurry there.  Just replace the parameter in your formula with that code.

if {@StartRange1} in {?StartRange1} to {?EndRange1} then

  would become

if {@StartRange1} in
 Mid (Right ("0" + {?StartRange1}, 6), 3, 4) + Left (Right ("0" + {?StartRange1}, 6), 2) to
 Mid (Right ("0" + {?EndRange1}, 6), 3, 4) + Left (Right ("0" + {?EndRange1}, 6), 2) then

 FWIW, if you don't already know, what that code does is add a "0" to the front of the parameter value, so, for example, "52013" would become "052013" and "112013" would become "0112013", and then it takes the rightmost 6 characters, which would give you "052013" and "112013".  IOW, it adds a leading "0" if the period is just one digit, so the parameter will look like ppyyyy.  Then it uses Mid to extract the year (4 characters, starting at the 3rd position) and the two digit period (the leftmost 2 characters) and concatenates them together.  So, "52013" becomes "201305" and "112013" becomes "201311".

 If you're going to be using those parameters in other formulas and need the values "converted" there too, you could create a formula for each parameter that "converts" the value.  For example:

// start_range_ppyyyy
Mid (Right ("0" + {?StartRange1}, 6), 3, 4) + Left (Right ("0" + {?StartRange1}, 6), 2)

// end_range_ppyyyy
Mid (Right ("0" + {?EndRange1}, 6), 3, 4) + Left (Right ("0" + {?EndRange1}, 6), 2)

 Then the earlier formula would be:

if {@StartRange1} in {@start_range_ppyyyy} to {@end_range_ppyyyy} then

 And, as I mentioned before, the way that I'm rearranging the parameter values is based on the assumption that they will _always_ look like pyyyy (for the periods below 10) or ppyyyy (for periods 10 and up).  If the parameter values could be different (maybe the user types them in and could just make a mistake), then you might want to add some error checking.  In that case, it would probably be easier to use a formula to "convert" each parameter, and include the error checks in those formulas.  You'd have to decide how you wanted the report to handle an invalid value (eg. if the user mis-typed the year and entered 5203 instead of 52013).


Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question