cancel
Showing results for 
Search instead for 
Did you mean: 

how to link a parameter to a formula

jopav613
Explorer
0 Kudos

I'm using Crystal Reports 2016. I have a report in which I created multiple parameters that successfully link to various fields. However, my current requirement is to link a parameter to a formula that I created but Crystal does not allow me to select this formula as the basis for this parameter. I tried creating a sub-report with a shared variable & linking this to my main report but Crystal does not allow me to select this shared variable either. Please advise. Thanks!

Accepted Solutions (0)

Answers (2)

Answers (2)

DellSC
Active Contributor

You can't link a formula to a parameter - the formulas don't process until after the parameters have been read. Can you post the formula here? Depending on what the formula does, there may be a way around this.

-Dell

jopav613
Explorer
0 Kudos

Hi Dell,

Ugh. The formula I created sums 2 numeric fields based on a condition. Really need this to link to a parameter somehow. My boss is on my case to get my project ready.

It's:

if {item.onorder} > 0 or

{item.onhand} > 0 then

{item.onorder} + {item.onhand}

Thanks.

DellSC
Active Contributor
0 Kudos

How does this need to link to a parameter? Do you need to filter this sum based on the parameter? If that's the case and you're linking tables together in the report instead of using a command or a stored procedure, you could create a SQL Expression that does this using a case statement and link that to the parameter.

SQL Expressions use the syntax of your database, not Crystal syntax. So, it might look like this:

case
  when "item"."onorder" > 0 or "item"."onhand" > 0 then "item"."onorder" + "item"."onhand"
  else 0
end

Because SQL Expressions become part of the select part of the query that Crystal generates, you can filter them based on parameters.

-Dell

Abdul
Active Contributor
0 Kudos

You can use case statement based on parameter in your query to sum two fields as its simple sum