Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Same function operating on different database fields?

Status
Not open for further replies.

pbalepur

IS-IT--Management
Apr 5, 2005
1
US
Pretty new to CR. Would appreciate a response from the gurus.

Is there a way to create a "parameterized" function that would accept the name of the database field as a parameter?

We have a table with N performance metrics. Need to summarize these using the PthPercentile(p,<metric column>,<group by column>) function.

I would like the user to be able to select the "metric" they want to summarize via a prompt / parameter and have the summary function operate on that user specified metric / column. Effectively, using this report / function as a "template".

Obviously, I can write N summary functions, one each for the individual metrics. Can I avoid that?

Thanks!
 
First, create a string parameter with options that describe your metrics, and then write a formula like the following:

if {?Metric} = "Cost" then
PthPercentile(90,{table.cost},{table.group}) else
if {?Metric} = "Quantity" then
PthPercentile(90,{table.quantity},{table.group}) else //etc.

If you also want to parameterize the "P" value, you would have to do it indirectly by using nested ifs, as in:

if {?Metric} = "Cost" then
(
if {?Percentile} = 90 then
PthPercentile(90,{Table.Cost},{Table.Group}) else
if {?Percentile} = 50 then
PthPercentile(50,{Table.Cost},{Table.Group})
) else
if {?Metric} = "Quantity" then
(
if {?Percentile} = 90 then
PthPercentile(90,{Table.Quantity},{Table.Group}) else
if {?Percentile} = 50 then
PthPercentile(50,{Table.Quantity},{Table.Group})
)

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top