@hshp/mdxjs
v1.0.1
Published
A copy of the [MDXpy](https://github.com/cubewise-code/mdxpy/tree/master) library, but in javascript, credits to them.
Readme
MDXjs
A copy of the MDXpy library, but in javascript, credits to them.
Install
npm install hshp@mdxjsMembers
The ElementMember class represents a element of an dimension.
const m0 = ElementMember.fromUniqueName("[Article].[a1]")
console.log(m0.uniqueName)
> "[Article].[Article].[a1]"
const m1 = ElementMember.fromUniqueName("[Article].[HCP].[a1]")
console.log(m1.uniqueName)
> "[Article].[HCP].[a1]"
const m2 = ElementMember.of("Article", "a1")
console.log(m2.uniqueName)
> "[Article].[Article].[a1]"
const m3 = ElementMember.of("Article", "HCP", "a1")
console.log(m3.uniqueName)
> "[Article].[HCP].[a1]"
const m4 = ElementMember.of("[Article].[HCP].[a1]")
console.log(m4.uniqueName)
> "[Article].[HCP].[a1]"
console.log(m3.equals(m4))
> trueThe CalculatedMember class extends the ElementMember class and represents a member in an MDX query.
const cm0 = CalculatedMember.aggregate(
"Article",
"HCP",
"CalcArticle",
MdxHierarchySet.members([m1, "[Article].[HCP].[a2]"])
)
console.log(cm0.toMdx())
> "MEMBER [Article].[HCP].[CalcArticle] AS AGGREGATE({[Article].[HCP].[a1],[Article].[HCP].[a2]})"
const cm1 = CalculatedMember.aggregate(
"Article",
"HCP",
"CalcArticle",
MdxHierarchySet.members([m1, "[Article].[HCP].[a2]"])
new MdxCellCoordinates('Cube', MdxTuple.of(Member.of("Product", "p1"), "[Measure].[Measure].[m1]"))
)
console.log(cm1.toMdx())
> "MEMBER [Article].[HCP].[CalcArticle] AS AGGREGATE({[Article].[HCP].[a1],[Article].[HCP].[a2]},[Cube].([Product].[Product].[p1],[Measure].[Measure].[m1]))"It includes methods for various MDX calculations.
aggregatedimension: string- The dimension of the elementhierarchy: string- The hierarchy of the elementelement: string- The element namemdxSet: MdxHierarchySet- Set expressionsmdxCellCoordinates?: MdxCellCoordinates- Optional numeric expression
avgdimension: string- The dimension of the elementhierarchy: string- The hierarchy of the elementelement: string- The element namemdxSet: MdxHierarchySet- Set expressionsmdxCellCoordinates?: MdxCellCoordinates- Optional numeric expression
countdimension: string- The dimension of the elementhierarchy: string- The hierarchy of the elementelement: string- The element namemdxSet: MdxHierarchySet- Set expressionsincludesEmptyCells: boolean = true- Whether to include empty cells in the count
maxdimension: string- The dimension of the elementhierarchy: string- The hierarchy of the elementelement: string- The element namemdxSet: MdxHierarchySet- Set expressionsmdxCellCoordinates?: MdxCellCoordinates- Optional numeric expression
mediandimension: string- The dimension of the elementhierarchy: string- The hierarchy of the elementelement: string- The element namemdxSet: MdxHierarchySet- Set expressionsmdxCellCoordinates?: MdxCellCoordinates- Optional numeric expression
mindimension: string- The dimension of the elementhierarchy: string- The hierarchy of the elementelement: string- The element namemdxSet: MdxHierarchySet- Set expressionsmdxCellCoordinates?: MdxCellCoordinates- Optional numeric expression
sumdimension: string- The dimension of the elementhierarchy: string- The hierarchy of the elementelement: string- The element namemdxSet: MdxHierarchySet- Set expressionsmdxCellCoordinates?: MdxCellCoordinates- Optional numeric expression
vardimension: string- The dimension of the elementhierarchy: string- The hierarchy of the elementelement: string- The element namemdxSet: MdxHierarchySet- Set expressionsmdxCellCoordinates?: MdxCellCoordinates- Optional numeric expression
varpdimension: string- The dimension of the elementhierarchy: string- The hierarchy of the elementelement: string- The element namemdxSet: MdxHierarchySet- Set expressionsmdxCellCoordinates?: MdxCellCoordinates- Optional numeric expression
lookupdimension: string- The dimension of the elementhierarchy: string- The hierarchy of the elementelement: string- The element namecube: string- The cube namemdxTuple: MdxTuple- The tuple for the cell coordinates
lookupFromCoordinatesdimension: string- The dimension of the elementhierarchy: string- The hierarchy of the elementelement: string- The element namemdxCellCoordinates: MdxCellCoordinates- Cell expression
lookupAttributedimension: string- The dimension of the elementhierarchy: string- The hierarchy of the elementelement: string- The element nameattributeDimension: string- The attribute dimensionattribute: string- The attribute name
lookupPropertydimension: string- The dimension of the elementhierarchy: string- The hierarchy of the elementelement: string- The element nameattributeDimension: string- The attribute dimensionattribute: string- The attribute name
MdxTuple
The MdxTuple class represents a tuple of ElementMenber objects.
const mt = MdxTuple.of(m1, "[Product].[Product].[p1]")
console.log(mt.toMdx())
> "([Article].[HCP].[a1],[Product].[Product].[p1])"
mt.addMember(Member.of("Version", "v1"))
console.log(mt.toMdx())
> "([Article].[HCP].[a1],[Product].[Product].[p1],[Version].[Version].[v1])"MdxSet
The MdxSet class represents a set in MDX. Provides various static methods to create different types of sets.
crossJoinssets: MdxSet[]- The sets to cross join
unionssets: MdxSet[]- The sets to unionallowDuplicates: boolean = false- Whether to allow duplicates in the union
tuplestuples: MdxTuple[]- The tuples to include in the set
MdxHierarchySet
The MdxHierarchySet class extends the MdxSet class.
const mhs0 = MdxHierarchySet.tm1SubsetAll("Article")
console.log(mhs0.toMdx())
> "{TM1SUBSETALL([Product].[Article])}"
const mhs1 = MdxHierarchySet.tm1DimensionSubsetToSet("Article", "End_User")
console.log(mhs1.toMdx())
> "{TM1SUBSETTOSET([Article].[Article],'End_User')}"
const mhs2 = MdxHierarchySet.allLeaves("Article")
console.log(mhs2.toMdx())
> "{TM1FILTERBYLEVEL({TM1SUBSETALL([Article].[Article])},0)}"Provides various static methods to create different types of sets.
tm1SubsetAlldimension: stringhierarchy?: string
allMembersdimension: stringhierarchy?: string
tm1SubsetToSetdimension: stringhierarchy: stringsubset: string
tm1DimensionSubsetToSetdimension: stringsubset: string
allConsolidationsdimension: stringhierarchy?: string
allLeavesdimension: stringhierarchy?: string
defaultMemberdimension: stringhierarchy?: string
membermember: ElementMember
membersmembers: ElementMember[]
parentmember: ElementMember
firstChildmember: ElementMember
lastChildmember: ElementMember
childrenmember: ElementMember
ancestorsmember: ElementMember
ancestormember: ElementMemberancestor: number
drillDownLevelmember: ElementMemberlevel: number
descendantsmember: ElementMemberlevelOrDepth?: MdxLevelExpressiondescFlag?: Order
fromStringdimension: stringhierarchy: stringmdx: string
rangestartMember: ElementMemberendMember: ElementMember
unionssets: MdxHierarchySet[]allowDuplicates: boolean = false
Instance methods to manipulate the set can be concatenated.
const mhs3 = MdxHierarchySet.tm1SubsetAll("Article").filterByLevel(0).filterByPattern("a3*").tm1Sort()
console.log(mhs3.toMdx())
> "{TM1SORT({TM1FILTERBYPATTERN({TM1FILTERBYLEVEL({TM1SUBSETALL([Article].[Article])},0)},'a3*')},ASC)}"filterByAttributeattributeName: stringattributeValues: (string | number)[]operator: string = '='
filterByPropertypropertyName: stringpropertyValues: (string | number)[]operator: string = '='typed: boolean = false
filterByPatternwildcard: string
filterByLevellevel: number
filterByElementTypeelementType: 'NUMERIC' | 'STRING' | 'CONSOLIDATED'
filterByCellValuecube: stringmdxTuple: MdxTupleoperator: stringvalue: string | number
filterByInstrcube: stringmdxTuple: MdxTuplesubstring: stringoperator: string = '>'position: number = 0caseInsensitive: boolean = 0
tm1Sortascending: boolean = true
hierarchizeheadhead: number
tailtail: number
subsetstart: numberlength: number
topCountcube: stringmdxTuple: MdxTupletop: number
bottomCountcube: stringmdxTuple: MdxTuplebottom: number
unionotherSet: MdxHierarchySetallowDuplicates: boolean = false
intersectotherSet: MdxHierarchySet
exceptotherSet: MdxHierarchySet
ordercube: stringmdxTuple: MdxTupleorder: 'ASC' | 'DESC' | 'BASC' | 'BDESC' = 'BASC'
orderByAttributeattributeName: stringorder: 'ASC' | 'DESC' | 'BASC' | 'BDESC' = 'BASC'
generateAttributeToMemberattribute: stringdimension: dimensionhierarchy?: string
tm1DrillDownMemberotherSet?: MdxHierarchySetrecursive: boolean = true
MdxBuilder
The MdxBuilder is used to build MDX queries. MdxSet are placed on the axes. Zero suppression can be switched on or off per axis. The actual MDX expression is generated with the toMdx method.
const mb = MdxBuilder.fromCube("Cube").addSetToColumnAxis(MdxHierarchySet.allLeaves("Article"))
console.log(mb.toMdx())
> "SELECT {TM1FILTERBYLEVEL({TM1SUBSETALL([Article].[Article])},0)} ON 0 FROM [CUBE]"
mb.columnsNonEmpty();
console.log(mb.toMdx())
> "SELECT NON EMPTY {TM1FILTERBYLEVEL({TM1SUBSETALL([Article].[Article])},0)} ON 0 FROM [CUBE]"Static method to create a MDX.
fromCubecube: string
Instance methods can be concatenated.
withMembermember: CalculatedMember
columnsNonEmptyrowsNonEmptyaddSetToColumnAxismdxSet: MdxSet
addSetToRowAxismdxSet: MdxSet
addMemberToWheremember: ElementMember
removeMemberFromWheremember: ElementMember
where...members: ElementMember[]
addPropertiesToColumnAxis...properties: ElementMember[]
addPropertiesToRowAxis...properties: ElementMember[]
