Hi Raghu.

I don't know about XPath, but maybe using XSLT might help you here:

Class Sample.XSLTransform [ Abstract ]
{

ClassMethod test()
{
    set tXML= ##class(%GlobalCharacterStream).%New()
    do tXML.Write("<HHSOS><DIAGNOSES><DIAGNOSIS_DATA><DIAGNOSIS_DATA_GUID>3762875</DIAGNOSIS_DATA_GUID><DIAGNOSIS_DATA_GUID>37628752</DIAGNOSIS_DATA_GUID></DIAGNOSIS_DATA><DIAGNOSIS_DATA></DIAGNOSIS_DATA><DIAGNOSIS_DATA></DIAGNOSIS_DATA><DIAGNOSIS_DATA_GUID>37628753</DIAGNOSIS_DATA_GUID></DIAGNOSES></HHSOS>")

    set tXSL=##class(%Dictionary.CompiledXData).%OpenId(..%ClassName(1)_"||ExampleXSL").Data

    set tSC=##class(%XML.XSLT.Transformer).TransformStream(tXML,tXSL,.tOutput)
    zwrite tSC
    set tSC=tOutput.OutputToDevice()
}

XData ExampleXSL
{
<?xml version="1.0"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
    <xsl:copy-of select="//DIAGNOSIS_DATA_GUID[1]"/>
</xsl:template>
</xsl:stylesheet>
}

}

SAMPLES>d ##class(Sample.XSLTransform).test()
tSC=1
<?xml version="1.0" encoding="UTF-8"?><DIAGNOSIS_DATA_GUID>3762875</DIAGNOSIS_DATA_GUID><DIAGNOSIS_DATA_GUID>37628753</DIAGNOSIS_DATA_GUID>

Conrad,

your question have two parts

a) For queries like

WHERE a = (select ...)

if subquery returns more than one row, Caché will compare left part with first value of subquery.

b) If several people are tied for the minimum age, then following query prints all of them

SELECT Age,Name,home_state
FROM Sample.Person p1
WHERE age =  (
    SELECT min(age)
    FROM Sample.Person p2
    WHERE p1.home_state = p2.home_state)

Documentation explains both functions well and with examples, so I encourage you to look into them. Especially first two examples for %ALL function

ALLMEMBERS -- function that returns a set of all members of the given level or hierarchy
http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=...

%ALL -- function that enables you to use a member while ignoring any ROW and COLUMN context that uses the hierarchy to which this member belongs.
http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=...

As to your question about calculating percentage of the top level, here is sample that for each product calculates revenue percentage of total from all products (2nd column) and from category for this product (3rd column).

Sample pivot

RevenuePctOfAllProducts and RevenuePctOfParent are calculated measures that defined as follows:

RevenuePctOfAllProducts:

Measures.[Amount Sold] / SUM(Product.[All Product].%ALL, Measures.[Amount Sold])

RevenuePctOfParent:

Measures.[Amount Sold] / SUM(Product.CurrentMember.Parent, Measures.[Amount Sold])

So the full query looks like:

WITH
MEMBER [MEASURES].[RevenuePctOfAllProducts] AS 
    'Measures.[Amount Sold] / SUM(Product.[All Product].%ALL, Measures.[Amount Sold])' 
MEMBER [MEASURES].[RevenuePctOfParent] AS 
    'Measures.[Amount Sold] / SUM(Product.CurrentMember.Parent, Measures.[Amount Sold])'
SELECT NON EMPTY {[Measures].[Amount Sold],
                  [MEASURES].[REVENUEPCTOFALLPRODUCTS],
                  [MEASURES].[REVENUEPCTOFPARENT]} ON 0,
    NON EMPTY HEAD(NONEMPTYCROSSJOIN([Product].[P1].[Product Category].Members,[Product].[P1].[Product Name].Members),2000) ON 1 
FROM [HOLEFOODS]

As far as I understand such usage of GROUP BY and select columns is not standard in SQL world.

That is -- if we GROUP BY some fields, then in SELECT list we can have either fields we group by or other fields as arguments of aggregate functions.

We can write

SELECT home_state, max(age)
FROM sample.person
GROUP BY home_state

But we cannot write

SELECT home_state, max(age), name
FROM sample.person
GROUP BY home_state

It is not clear -- what name out of all rows that have the same home_state do we want.

Consider following data in Sample.Person:

Age Name Home_State
10  John MA
10  Jim  MA

What name will following query return John or Jim?

SELECT Age,Name
FROM Sample.Person
GROUP BY Home_State
HAVING Age = MIN(Age)

I prefer following variant of the query with join:

SELECT Age,Name,home_state
FROM Sample.Person p1
WHERE age =  (
    SELECT min(age)
    FROM Sample.Person p2
    WHERE p1.home_state = p2.home_state)

That returns both rows from the sample data above.

Attila, can you please elaborate on why it is potentially dangerous to refer to data outside of current record unless Calculated is specified?

I personally use Calculated only when property value might change during oref lifetime. If property value is not changed once object is in process memory, then there is no need for Calculated, as I understand -- Transient is enough.

Yes, Illegal CSP Request usually means that access to this particular class is prohibited.

If your web application named '/csp/healthshare/mhclib/' then you need to enable classes as follows:

set ^SYS("Security","CSP","AllowClass","/csp/healthshare/mhclib/","%SOAP.WebServiceInfo")=1
set ^SYS("Security","CSP","AllowClass","/csp/healthshare/mhclib/","%SOAP.WebServiceInvoke")=1

Notice that calling SOAP Service via test webpage (%SOAP.WebServiceInvoke.cls) is independent from calling web service via SOAP protocol. For that you should check option "Inbound Web Services" in Web application settings.

%SOAP.WebServiceInfo and %SOAP.WebServiceInvoke are just pages to test web services via Browser.

SOAP protocol itself does not use these pages.

Message
"An error occurred with the CSP application and has been logged to system error log (^ERRORS)"

means that you can check error in Management Portal -> System Operation -> System Logs -> Application Error Log -> [Namespace]

Or for debugging purposes set error page for web application to %CSP.Error.cls
http://docs.intersystems.com/cache20161/csp/docbook/DocBook.UI.Page.cls?...

and see errors on the page itself