This recipe shows you how to create a Mondrian 4 cube. Basically, this is the second part, after the physical model. It is responsible for mapping the business side to the physical schema.
Proceed with the following steps:
<Cube name='Orders' defaultMeasure='Total Price'></Cube>
Cube
tag:<Dimensions> <Dimension name='Product' table='Orders' key='Product Code'> <Attributes> <Attribute name='Name' keyColumn='productName' hasHierarchy='false'/> <Attribute name='Product Code' keyColumn='productCode' hasHierarchy='false'/> </Attributes> <Hierarchies> <Hierarchy name='Product' hasAll='true'> <Level attribute='Name'/> </Hierarchy> </Hierarchies> </Dimension> </Dimensions>
<Dimension name='Customer' table='Orders' key='Product Code'> <Attributes> <Attribute name='Country' keyColumn='customerCountry' hasHierarchy='false'/> <Attribute name='Name' keyColumn='customerName' hasHierarchy='false'/> <Attribute name='Product Code' keyColumn='customerNumber' hasHierarchy='false'/> </Attributes> <Hierarchies> <Hierarchy name='Customer' hasAll='true'> <Level attribute='Country'/> <Level attribute='Name'/> </Hierarchy> </Hierarchies> </Dimension>
<MeasureGroups> <MeasureGroup name='Orders' table='Orders'> <Measures> <Measure name='Total Price' column='totalPrice' aggregator='sum' formatString='Standard'/> <Measure name='Quantity Ordered' column='quantityOrdered' aggregator='sum' formatString='Standard'/> </Measures> <DimensionLinks> <FactLink dimension='Product'/> <FactLink dimension='Customer'/> </DimensionLinks> </MeasureGroup> </MeasureGroups>
Avg Price Each
calculated measure to the Orders cube, writing these lines inside the Cube
tag and after the MeasureGroups
tag:<CalculatedMembers> <CalculatedMember name='Avg Price Each' dimension='Measures'> <Formula>IIF([Measures].[Quantity Ordered]=0,0,[Measures].[Total Price]/[Measures].[Quantity Ordered])</Formula> <CalculatedMemberProperty name='MEMBER_ORDINAL' value='9'/> </CalculatedMember> </CalculatedMembers>
MongoDBPentahoCookbook.mondrian.xml
.In this second part, we created the proper logical cube with dimensions, measures, and calculated measures.
As we did in the previous recipes for Mondrian 3.x versions, we created two dimensions: products and customers. The product dimension has just one level, which is the name, and the customer dimension has two levels, namely the country and the customer name.
In Mondrian 4, one of the good features compared to the Mondrian 3.x version is measure groups. In Mondrian 3.x, cubes have only one fact
physical table. If you want to create a cube with different fact
tables joined together, you need to use a virtual cube. A virtual cube combines multiple cubes. However, this approach is no longer supported with Mondrian 4, and you need to use measure groups.
In this example, we created only one measure group. In other scenarios, it can be necessary to create more than one, with two measures: Total Price and Quantity Ordered.
After the measures, we created a calculated measure, as we did for Mondrian 3.x in previous recipes, called Avg Price Each. Basically, this is Total Price divided by Quantity Ordered, giving the average product price per order.