How to use Xpath in Infopath

P

Per [Pedalen]

Hi,

I am trying to create a quite complicated expression to summarize a part of
a node set. As I write it below is not working, though I beleive it is the
best way to explain my problem.

I am working in Infopath as it is my interface, and I am using a web service
to collect information from a CRM database. The resulting XML document I am
working on...

sum(May[Phase = "4"] * (Probability[Phase = "4"] / 100))

Phase is phase in the sales cycle; Probability is closeprobability in the
sales cycle.

First of all I want to calculate a weighted value as this example...
(50000 * (90/100)) which should result in 45000.
Second I want to summarize all my calculated values (calculated from my
nodeset).

Does anyone know how to do this in Xpath for Infopath?
 
P

Per [Pedalen]

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?

KjellSJ said:
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


Per said:
Hi,

I am trying to create a quite complicated expression to summarize a part of
a node set. As I write it below is not working, though I beleive it is the
best way to explain my problem.

I am working in Infopath as it is my interface, and I am using a web service
to collect information from a CRM database. The resulting XML document I am
working on...

sum(May[Phase = "4"] * (Probability[Phase = "4"] / 100))

Phase is phase in the sales cycle; Probability is closeprobability in the
sales cycle.

First of all I want to calculate a weighted value as this example...
(50000 * (90/100)) which should result in 45000.
Second I want to summarize all my calculated values (calculated from my
nodeset).

Does anyone know how to do this in Xpath for Infopath?
 
K

KjellSJ

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


Per said:
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?

KjellSJ said:
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


Per said:
Hi,

I am trying to create a quite complicated expression to summarize a part of
a node set. As I write it below is not working, though I beleive it is the
best way to explain my problem.

I am working in Infopath as it is my interface, and I am using a web service
to collect information from a CRM database. The resulting XML document I am
working on...

sum(May[Phase = "4"] * (Probability[Phase = "4"] / 100))

Phase is phase in the sales cycle; Probability is closeprobability in the
sales cycle.

First of all I want to calculate a weighted value as this example...
(50000 * (90/100)) which should result in 45000.
Second I want to summarize all my calculated values (calculated from my
nodeset).

Does anyone know how to do this in Xpath for Infopath?
 
P

Per [Pedalen]

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>
....

KjellSJ said:
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


Per said:
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?

KjellSJ said:
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,

I am trying to create a quite complicated expression to summarize a part of
a node set. As I write it below is not working, though I beleive it is the
best way to explain my problem.

I am working in Infopath as it is my interface, and I am using a web service
to collect information from a CRM database. The resulting XML document I am
working on...

sum(May[Phase = "4"] * (Probability[Phase = "4"] / 100))

Phase is phase in the sales cycle; Probability is closeprobability in the
sales cycle.

First of all I want to calculate a weighted value as this example...
(50000 * (90/100)) which should result in 45000.
Second I want to summarize all my calculated values (calculated from my
nodeset).

Does anyone know how to do this in Xpath for Infopath?
 
K

KjellSJ

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

Per said:
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>
...

KjellSJ said:
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


Per said:
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"))

"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,

I am trying to create a quite complicated expression to summarize a part of
a node set. As I write it below is not working, though I beleive it is the
best way to explain my problem.

I am working in Infopath as it is my interface, and I am using a web service
to collect information from a CRM database. The resulting XML document I am
working on...

sum(May[Phase = "4"] * (Probability[Phase = "4"] / 100))

Phase is phase in the sales cycle; Probability is closeprobability in the
sales cycle.

First of all I want to calculate a weighted value as this example...
(50000 * (90/100)) which should result in 45000.
Second I want to summarize all my calculated values (calculated from my
nodeset).

Does anyone know how to do this in Xpath for Infopath?
 
P

Per [Pedalen]

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.

KjellSJ said:
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

Per said:
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>
...

KjellSJ said:
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
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"))

"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,

I am trying to create a quite complicated expression to summarize a part of
a node set. As I write it below is not working, though I beleive it is the
best way to explain my problem.

I am working in Infopath as it is my interface, and I am using a web service
to collect information from a CRM database. The resulting XML document I am
working on...

sum(May[Phase = "4"] * (Probability[Phase = "4"] / 100))

Phase is phase in the sales cycle; Probability is closeprobability in the
sales cycle.

First of all I want to calculate a weighted value as this example...
(50000 * (90/100)) which should result in 45000.
Second I want to summarize all my calculated values (calculated from my
nodeset).

Does anyone know how to do this in Xpath for Infopath?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top