Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / May 2005

Tip: Looking for answers? Try searching our database.

How to use Xpath in Infopath

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Per [Pedalen] - 03 May 2005 15:47 GMT
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?
KjellSJ - 03 May 2005 19:32 GMT
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?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.