Wednesday, March 8, 2017

Finally...A discussion of how to unroll dimension hierarchies

A quick note today.  I finally found a good discussion of how to unroll dimension hierarchies (such as default dimensions on Sales Orders/Lines or Purchase Orders/Lines)

http://axmasterclass.com/blog/financial-dimensions-deep-dive/

Working through the notes, I finally developed this query (first pass and will probably need improvement.

SELECT CT.ACCOUNTNUM [Acct #], DTC.NAME [Account Name],
DAVSI.DISPLAYVALUE [Location Num], DT.NAME [Location Name],
SUM(CIT.LINEAMOUNT) [Total Sales]
FROM DIMENSIONATTRIBUTEVALUESETITEM DAVSI
INNER JOIN DIMENSIONATTRIBUTEVALUE DAV ON DAVSI.DIMENSIONATTRIBUTEVALUE=DAV.RECID
     AND DAVSI.PARTITION = DAV.PARTITION
INNER JOIN DIMENSIONATTRIBUTE DA ON DAV.DIMENSIONATTRIBUTE=DA.RECID
     AND DAV.PARTITION = DA.PARTITION
INNER JOIN DIRPARTYTABLE DT ON DT.OMOPERATINGUNITNUMBER = DAVSI.DISPLAYVALUE
     AND DT.OMOPERATINGUNITTYPE=6
     AND DT.INSTANCERELATIONTYPE = 2377
INNER JOIN CUSTINVOICEJOUR CIJ ON CIJ.DEFAULTDIMENSION = DAVSI.DIMENSIONATTRIBUTEVALUESET
     AND CIJ.PARTITION = DAVSI.PARTITION
INNER JOIN CUSTINVOICETRANS CIT ON CIT.INVOICEID = CIJ.INVOICEID
     AND CIT.INVOICEDATE = CIJ.INVOICEDATE
     AND CIT.SALESID = CIT.SALESID
     AND CIT.NUMBERSEQUENCEGROUP = CIJ.NUMBERSEQUENCEGROUP
INNER JOIN CUSTTABLE CT ON CT.ACCOUNTNUM = CIJ.ORDERACCOUNT
     AND CT.DATAAREAID = CIJ.DATAAREAID
     AND CT.PARTITION = CIJ.PARTITION
INNER JOIN DIRPARTYTABLE DTC ON DTC.RECID = CT.PARTY
     AND DTC.PARTITION = CT.PARTITION
WHERE DA.NAME = 'my specific dimension...check the table for a list of values'
GROUP BY DAVSI.DISPLAYVALUE, DT.NAME, CT.ACCOUNTNUM, DTC.NAME, CT.CREDITMAX
ORDER BY DAVSI.DISPLAYVALUE, CT.ACCOUNTNUM

No comments:

Post a Comment