Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Return a specific field help Post Reply Post New Topic
Author Message
bCritter
Newbie
Newbie
Avatar

Joined: 23 Oct 2012
Location: Canada
Online Status: Offline
Posts: 2
Quote bCritter Replybullet Topic: Return a specific field help
    Posted: 23 Oct 2012 at 4:15pm
Good evening
 
I have a table with main categories followed by sub categories.
 
Example:
 
100      Fruits            <-- Main category
100.1   Apples          <-- Sub category
200      Vegetables   <-- Main category
200.1   Carrots         <-- Sub category
etc...
 
I have grouped the report on the main categories easily enough but I can't figure out for the life of me how to get the description label to return only the main category description (ie: Fruits, Vegetables, etc...)
 
I figured out how to return the proper description with a Select Case formula but there are over 25 main categories & I'm sure there has to be a simpler way.  Could somebody please help point me in the right direction.
 
Thanks kindly
bCritter Smile
 
IP IP Logged
comatt1
Senior Member
Senior Member
Avatar

Joined: 19 May 2011
Online Status: Offline
Posts: 337
Quote comatt1 Replybullet Posted: 24 Oct 2012 at 2:50am
well you can test for the decimal point if the main groups dont have them, or use a modulo function to examine division that leaves a remainder.

I would try

if totext({field}) like '%.%' then suppress

if you convert to text, the main fields may get a .00 after so 200 will become 200.00

so use replace(totext({field}, '.00', '') instead.

Otherwise if you use mod

if mod(100,{field}) <> 0 then dont suppress
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 24 Oct 2012 at 9:04am
Are all of the category fields always just three digits or are they defined by the fact that they don't have decimal places?  Do you want to roll up data from the subgroups to the main group level?
 
I would try to create a formula that looks something like this:
 
left({MyTable.CategoryField}, InStr({MyTable.CategoryField}, '.') - 1)
 
Then group on this formula and sort on the Category Field.  This will always get you the main category as the first record in the group.  You can then put your data in a Group Header section to get just the main group listing.
 
This method assumes that you want to include the subgroup data in the query so that you can do sums or counts or something of the sort.
 
If you don't want the subgroup data to appear in the report at all, there's a way to filter for that - however, it's more efficient to do that in the query than it is to use a Crystal formula for it - if you use a Crystal formula, Crystal will bring ALL of the data into memory and filter it there.  What type of database are you connecting to?  With that information I can probably give you the exact syntax to use for the filter to get this done in the database.
 
-Dell
IP IP Logged
bCritter
Newbie
Newbie
Avatar

Joined: 23 Oct 2012
Location: Canada
Online Status: Offline
Posts: 2
Quote bCritter Replybullet Posted: 24 Oct 2012 at 9:55am
Thank you both Comatt1 and hilfy for taking the time to assist me. 
 
I will try both your suggestions and post back as soon as I can.
 
Hilfy, to answer a couple of your questions:
 
The main category is always 3 digits followed by a decimal and the sub categories are always the first 3 digits of the main category a decimal and then 4 more digits (ie: 100.1234). I'm actually dealing with assets/equipment & I apologize for not being very clear on that, but I was trying to make my example as simple as possible. I should also add that not all main categories will have a sub category.
 
I have everything grouped by the first 3 digits but when I try to return the main category name, I get the name of the sub category for the first item in the group.  I understand what you're saying about sorting on the category field but I need the list to sort by the AssetId nbr so I don't think that your suggestion will work.  I will try it though just to make sure.
 
As for whether I want subgroup data to appear in the report at all, I do definitely need to include it so a filter won't work.
 
I will let you know how I make out.
 
Again, thank for your assistance.  It is greatly appreciated.
 
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 24 Oct 2012 at 10:38am

Create a formula for the sort:

 
If {MyTable.CategoryField} = {@GroupFormula} then '*'
else {MyTable.AssetID}
 
If the Asset ID field is a number, use -1 instead of '*'.  This should get your main category to the top of the list.
 
-Dell
IP IP Logged
Post Reply Post New Topic
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



This page was generated in 0.031 seconds.