Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Have maximum of "x", need dinamyc label for it Post Reply Post New Topic
Author Message
Hugo Afonso
Newbie
Newbie
Avatar

Joined: 20 Jun 2012
Location: Portugal
Online Status: Offline
Posts: 4
Quote Hugo Afonso Replybullet Topic: Have maximum of "x", need dinamyc label for it
     Posted: 20 Jun 2012 at 11:36pm
Hello.

This is my first post in this forum, so I apologize if it is a duplicate. I've found something similar, but not exactly the same...

Here's my issue:

I have a calculated field, "unit price", to which I requested the maximum value (the highest price).

So far, so good: i get a cell with the value.

But here's my dillema:
I only have the value - the highest price, but not it's name, which is part of a list of products.
An example could be that, this month, the highest price is for "tennis balls", but next month it's "golf balls".
If I only have the number, in the report, I can't tell one from the other, as I only get the number.

I've tried formulas, but I'm also new to the syntax of CR, so "select" doesn't do what I expected it to do...

Thank you for your help!
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 20 Jun 2012 at 11:53pm

I'm not certain if this will work as I've never actually tried it but it should get you started if it doesn't get you all the way there, let me know how it goes.

 
NameCalc
if {@unitprice} = maximum({@unitprice},{@group}) // assuming you're grouping by month??
then "z" & {table.itemname}
else "a"
 
ItemName
mid(nthlargest(1,{@namecalc},{@group}),2) //again grouped by month?
 
Drag the item name formula field where you wish to display "Tennis Balls" or "Golf Balls" etc.
 
Regards,
Ryan.


Edited by rkrowland - 20 Jun 2012 at 11:54pm
IP IP Logged
Hugo Afonso
Newbie
Newbie
Avatar

Joined: 20 Jun 2012
Location: Portugal
Online Status: Offline
Posts: 4
Quote Hugo Afonso Replybullet Posted: 21 Jun 2012 at 12:50am
Thanks for the suggestion!

To clarify, I didn't group by month: I grouped by product. But even that is too many lines in the report.
My goal is to have two cells with the results: the list is just to validate data.

NameCalc (I called Max Unit Price) works ok, but depends on function Item Name.

The mid function is OK, but the nthlargest gave a problem:
"The function call does not match any overloads of nthlargest". Here is the formula:

mid(nthlargest({@Unit Price (Calculation)}), eFashion.Product\Category},2)

What's wrong with this picture...?
Again, thanks for the help!
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 21 Jun 2012 at 1:47am
Originally posted by Hugo Afonso

mid(nthlargest({@Unit Price (Calculation)}), eFashion.Product\Category},2)
 
Amend to;
 
mid(nthlargest(1,{@Unit Price (Calculation)},{eFashion.Product\Category}),2)
 
Regards,
Ryan.
IP IP Logged
Hugo Afonso
Newbie
Newbie
Avatar

Joined: 20 Jun 2012
Location: Portugal
Online Status: Offline
Posts: 4
Quote Hugo Afonso Replybullet Posted: 21 Jun 2012 at 9:24pm
I'm afraid there is still an error:

The function call does not match any overloads of mid.

From what I understand, this is because there are multiple options for "mid" function, instead of pin-pointing just one.

Is this the rationale?

Regards,
Hugo

Edited by Hugo Afonso - 21 Jun 2012 at 9:24pm
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 21 Jun 2012 at 11:08pm
There's is only 2 options included for the mid function, mid(nthlargest,2) - which is the correct syntax.
 
The problem is with the namecalc formula not being available for evaluation.
 
Looks to me this method isn't viable, so, you have 2 options.
 
1 - Sort your records descending by unitprice, this way you can simple drag unitprice and unit name into a summary header/footer to obtain the max unit.
 
2 - Subreports, if number 1 isn't an option we can go into more detail on this.
 
Regards,
Ryan.
IP IP Logged
Hugo Afonso
Newbie
Newbie
Avatar

Joined: 20 Jun 2012
Location: Portugal
Online Status: Offline
Posts: 4
Quote Hugo Afonso Replybullet Posted: 22 Jun 2012 at 3:36am
I'll dive into subreports and let you know of any doubts.

Thanks for the help so far!!
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