# Formulas

• ### Question

• Hello guys,

I having problem getting formulas from database into a field in my report.

These formulas are being stored in a table at the database as

QTY                      Formula
----------------------------------
1                            W+3
2                            W-2
3                            H+4
...                           ....
...                          .....
and so on

Where

W= Width Field
H= Height Field

Now, these formulas are strings and the oparation can't be preformed.

How do I Preform these formulas

What I did is that I convert that field to Decimal using Dce(Fields!Formula.value) But it doesn't work.

So, I had to replace both the H and the W with its Fields expressions in the database, but it is still not working!

Thursday, March 19, 2009 9:08 PM

• Reporting Services does not expose an expression parser for taking arbitrary strings and converting them to expressions that can be evaluated... that would be a tricky thing to build since we'd have no control over what the expressions could be.

If your expressions are always as simple as the ones that you've shown in your example, you could build your own expression parser using a calcualted field expression.  That wouldn't be easy, but it can be done.  You expression would look something like this:

'=iif(InStr(Fields.Formula.Value,"+"),
Dec(iif(Split(Fields.Formula.Value,"+")(0)="W",Parameters!Width.Value,Parameters!Height.Value)) +
Dec(Split(Fields.Formula.Value,"+")(1)),
iif(InStr(Fields.Formula.Value,"-"),
Dec(iif(Split(Fields.Formula.Value,"+")(0)="W",Parameters!Width.Value,Parameters!Height.Value)) -
Dec(Split(Fields.Formula.Value,"+")(1)),0))

Note this is just a sample, and yours would likely have to be much bigger and would need to do the right substitutution for W and H.

Paul

This posting is provided "AS IS" with no warranties, and confers no rights.
Friday, March 20, 2009 4:59 AM

### All replies

• Reporting Services does not expose an expression parser for taking arbitrary strings and converting them to expressions that can be evaluated... that would be a tricky thing to build since we'd have no control over what the expressions could be.

If your expressions are always as simple as the ones that you've shown in your example, you could build your own expression parser using a calcualted field expression.  That wouldn't be easy, but it can be done.  You expression would look something like this:

'=iif(InStr(Fields.Formula.Value,"+"),
Dec(iif(Split(Fields.Formula.Value,"+")(0)="W",Parameters!Width.Value,Parameters!Height.Value)) +
Dec(Split(Fields.Formula.Value,"+")(1)),
iif(InStr(Fields.Formula.Value,"-"),
Dec(iif(Split(Fields.Formula.Value,"+")(0)="W",Parameters!Width.Value,Parameters!Height.Value)) -
Dec(Split(Fields.Formula.Value,"+")(1)),0))

Note this is just a sample, and yours would likely have to be much bigger and would need to do the right substitutution for W and H.

Paul

This posting is provided "AS IS" with no warranties, and confers no rights.
Friday, March 20, 2009 4:59 AM
• Sorry for being late bro! Thanks for anwering my question, I had to work around it.

Thanks again.

Aash

Friday, March 27, 2009 4:19 PM