Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
255
Using a map with values to evaluate formula
posted

Hi,

I'm working with the Calculation Manager and I need your help. I have a formula which uses a "list" that I have added to formula editor. My question is if there is a way to pass the formula and the list of "Properties" to evaluate?

for instance:

the formula is like: if(Find("X20", [Attribute X], 1)=1, [Attribute A], [Attribute B]) where [Attribute X], [Attribute A] and [Attribute B] are part of the list that I have added to the formula editor.

And I only give a dictionary (or any other map, list, etc) with the values, like:

Dictionary<string, object> objects = new Dictionary<string, object>();
objects.Add("[Attribute X]", "VLX20");
objects.Add("[Attribute A]", 20);
objects.Add("[Attribute B]", 10);
And the calculation manager perform the operation of parse the formula to values and evaluate it.

Can we do that with the Calculation manager or other tool?

Thanks in advance.

Claudio Herrera

Parents
  • 34510
    Verified Answer
    Offline posted

    Hi Claudio,

    If that dictionary has been added to the calculation manager you should see some properties pertaining to it in the operand tree of the formula editor dialog.  These properties, however, will only be Key and Value.  You won't be able to refer to them by "Attribute X" etc.  You should be able to double click on Key or Value and it will add the necessary syntax to the expression.  For example, in my sample it looks like "[//ObjectsCalculator/Value(0)]" where 0 is the index of the value in the dictionary.  ObjectsCalculator is the ListCalculator that I'm using for this sample.

    So if I follow your example, the formula I would get is:

    IF ( FIND ( "X20", [//ObjectsCalculator/Value(0)], 1 ) = 3, [//ObjectsCalculator/Value(1)], [//ObjectsCalculator/Value(2)] )

    You'll see that instead of names I'm referring to the index of the value in the dictionary.  0 is "Attribute X", 1 is "Attribute A" and 2 is "Attribute B".  You'll also notice that instead of comparing the return value of FIND to 1 I'm comparing it to 3.  FIND returns the position in the string where the found text starts.  Since the value of the first item in the dictionary is "VLX20", "X20" starts on the 3rd position.

    WpfApplication1.zip
Reply Children
No Data