You should look into using the eval function:
sum(eval(group2, "field1 * field2"))
"Returns the values of a set of fields. The first argument defines the set
of fields; the second argument defines the expression to calculate for the
set of fields. Usually, the eval function is nested within a function that
operates on a set of fields, such as sum or avg."
http://office.microsoft.com/en-us/assistance/HP011552811033.aspx
KjellSJ
http://kjellsj.blogspot.com
> Hi,
>
[quoted text clipped - 17 lines]
>
> Does anyone know how to do this in Xpath for Infopath?
Per [Pedalen] - 03 May 2005 20:41 GMT
Thank you for your answer but actually I have already tried this and I can´t
really figure it out how to make this work. Now I have to add that this is
almost my first time working with Xpath and Infopath so it kind of
complicates things.
I tried this eval function in two ways though below is the most likely way
(I think ?!?);
sum(eval(result[Phase = "4"], May * Probability / 100))
Does anyone have any example of making things work with the sum and eval
functions?
> You should look into using the eval function:
> sum(eval(group2, "field1 * field2"))
[quoted text clipped - 30 lines]
> >
> > Does anyone know how to do this in Xpath for Infopath?
KjellSJ - 04 May 2005 07:51 GMT
How does your XML look ? What are elements and what are attributes ? Is your
casing of the XPath correct ? XPath in InfoPath is no different than XPath in
general.
If Phase is an attribute, your expression should look like this:
sum(eval(result[@Phase = "4"], "May * Probability / 100"))
Also check the full XPath expression in the formula builder.
Use more parenthesis in math expression that involves / as this is also an
XPath operator.
KjellSJ
http://kjellsj.blogspot.com
> Thank you for your answer but actually I have already tried this and I can´t
> really figure it out how to make this work. Now I have to add that this is
[quoted text clipped - 42 lines]
> > >
> > > Does anyone know how to do this in Xpath for Infopath?
Per [Pedalen] - 04 May 2005 08:32 GMT
As below is part om the resultset I receive from CRM/FetchXML.
As this shows for example I wish to multiply each April with the probability
divided by 100 and then summarize for each phase.
<?xml version="1.0" encoding="utf-8" ?>
- <resultset>
- <result>
<April>5000</April>
<Phase>5</Phase>
<Probability>90</Probability>
</result>
- <result>
<February>25000</February>
<March>5000</March>
<Phase>5</Phase>
<Probability>90</Probability>
</result>
...
> How does your XML look ? What are elements and what are attributes ? Is your
> casing of the XPath correct ? XPath in InfoPath is no different than XPath in
[quoted text clipped - 56 lines]
> > > >
> > > > Does anyone know how to do this in Xpath for Infopath?
KjellSJ - 04 May 2005 10:34 GMT
This formula works (used in an Expression Box control):
sum(eval(result[Phase = 5]; "April * Probability div 100"))
I have tested it using using this XML:
<?xml version="1.0" encoding="utf-8" ?>
<resultset>
<result>
<April>6000</April>
<Phase>5</Phase>
<Probability>90</Probability>
</result>
<result>
<April>5000</April>
<Phase>5</Phase>
<Probability>70</Probability>
</result>
<result>
<April>3000</April>
<Phase>4</Phase>
<Probability>10</Probability>
</result>
</resultset>
If you still can get it to work with your XML resultset, try to normalize it
so that all <result> elements always contains the same elements. InfoPath
does not like missing elements in calculations. Empty elements is OK, as by
default "" is regarded as 0 in calculations (see Tools-Form Options-General).
KjellSJ
http://kjellsj.blogspot.com
> As below is part om the resultset I receive from CRM/FetchXML.
>
[quoted text clipped - 76 lines]
> > > > >
> > > > > Does anyone know how to do this in Xpath for Infopath?
Per [Pedalen] - 04 May 2005 11:52 GMT
That is just a way I tried though something is wrong for me if the formula
works for you. I will try to normalize.
Thanks.
> This formula works (used in an Expression Box control):
> sum(eval(result[Phase = 5]; "April * Probability div 100"))
[quoted text clipped - 107 lines]
> > > > > >
> > > > > > Does anyone know how to do this in Xpath for Infopath?