Difference between revisions of "MDX Calculations"

(See Also)
 
(23 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 
__TOC__
 
__TOC__
Not all OLAP environments are as rich as we, the analysts would like. These examples show how XLCubed allows the power of OLAP to be simply used to improve our analyses.
+
Not all OLAP environments are as rich as we, the analysts would like. These examples show how FluenceXL allows the power of OLAP to be simply used to improve our analyses.
  
==Creating Calculated Members (based on the [[BicycleSales Demo Cube|Bicycle Sales cube]])==
+
For Fluence and Anaplan connections there is a [[XLCubed_MDX_Calculation_Support|list of supported MDX functions]].
  
 +
==Creating Calculated Members ==
 +
 +
To create a custom calculated member, open the '''Manage Calculations''' dialog from the {{Menu|FluenceXL|Custom Calculations}} ribbon option.
 +
 +
Select the '''Insert a new calculated member''' toolbar button ([[File:NewCalculatedMember.png]]). This will create a new blank calculation from which you can fill in the following fields:
 +
* '''Name''': The name for the new calculated member.
 +
* '''Parent hierarchy''': The hierarchy the calculated member will belong to.
 +
*'''Parent member''': The unique name of the parent member for the new calculation. If no member is specified, the calculated member will be created at the top level of the hierarchy.
 +
*'''Expression''': The MDX expression for the calculated member. You can use the treeview on the left to drag and drop members into the expression.
 +
 +
 +
All calculated members in the workbook appear on the left. Any calculation can be edited by selecting it in this control and then overwriting the fields on the right.
 +
 +
To delete a calculation, select the desired calculation and click the '''Delete the selected calculation''' toolbar button.
 +
 +
 +
===Example (based on the [[BicycleSales Demo Cube|Bicycle Sales cube]])===
 
''We will create new Gross Profit and Gross Profit Margin measures.''
 
''We will create new Gross Profit and Gross Profit Margin measures.''
  
Line 9: Line 26:
  
 
To create the calculated measures:
 
To create the calculated measures:
 +
<ol>
 +
<li value="1">Open the '''Manage Calculations''' dialog ({{Menu|FluenceXL|Custom Calculations}}). </li>
 +
<li value="2">To create the {{Code|Gross Profit}} member, click the '''Insert a new calculated member''' toolbar button</li>
 +
<li value="3"> A new 'untitled' member will appear. Fill in the following details for the new member:</li>
  
# Open the '''Manage Calculations''' dialog by selecting the {{Menu|XLCubed|Custom Calculations}} ribbon or menu option.
 
# To create the {{Code|Gross Profit}} member, click the '''Insert a new calculated member''' toolbar button ([[File:NewCalculatedMember.png]]).
 
# A new 'untitled' member will appear. Fill in the following details for the new member:
 
 
{{TableHeader}}
 
{{TableHeader}}
 
! scope="row" | Name
 
! scope="row" | Name
Line 26: Line 44:
 
| [KeyFigures].[All].&[Revenue] - [KeyFigures].[All].&[Cost of Sales] - [KeyFigures].[All].&[Production Costs]
 
| [KeyFigures].[All].&[Revenue] - [KeyFigures].[All].&[Cost of Sales] - [KeyFigures].[All].&[Production Costs]
 
{{TableFooter}}
 
{{TableFooter}}
[[File:CustomCalculations1.png|center|thumb|500px|alt=Custom calculations dialog with the Gross Profit member|The Gross Profit member]]
 
  
#<li value="4"> Create a second calculated member for the '''Gross Profit Margin''' member, and fill in the following details. To enter the format string, '''Show advanced controls''' must be clicked:
+
[[File:CustomCalculations1.png|center|thumb|400px|alt=Custom calculations dialog with the Gross Profit member|The Gross Profit member]]
 +
 
 +
 
 +
<li value="4"> Create a second calculated member for the '''Gross Profit Margin''' member, and fill in the following details. To enter the format string, '''Show advanced controls''' must be clicked:</li>
 
{{TableHeader}}
 
{{TableHeader}}
 
! scope="row" | Name
 
! scope="row" | Name
Line 45: Line 65:
 
| 0%
 
| 0%
 
{{TableFooter}}
 
{{TableFooter}}
[[File:CustomCalculations2.png|center|thumb|500px|alt=Custom calculations dialog with the Gross Profit Margin member|The Gross Profit Margin member]]
 
  
#<li value="5"> We now have members in the {{Code|KeyFigures}} hierarchy, but if we want to use them as normal measures, we need to create two more members in the {{Code|Measures}} hierarchy:
+
[[File:CustomCalculations2.png|center|thumb|400px|alt=Custom calculations dialog with the Gross Profit Margin member|The Gross Profit Margin member]]
 +
 
 +
 
 +
<li value="5"> We now have members in the {{Code|KeyFigures}} hierarchy, but if we want to use them as normal measures, we need to create two more members in the {{Code|Measures}} hierarchy:</li>
 
{{TableHeader}}
 
{{TableHeader}}
 
! scope="row" | Name
 
! scope="row" | Name
Line 79: Line 101:
 
{{TableFooter}}
 
{{TableFooter}}
  
#<li value="6"> Click on '''OK''' to create the calculated members.
+
<li value="6"> Click on '''OK''' to create the calculated members.</li>
 +
</ol>
  
 
We can now see the new measures in context. Let's find badly performing product groups for {{Code|2004}}.
 
We can now see the new measures in context. Let's find badly performing product groups for {{Code|2004}}.
# Click on the {{Menu|XLCubed|Grid}} ribbon item (or the {{Menu|XLCubed|Design Grid}} menu item in Excel 2003 and below). For more information about using this dialog, see [[Report Designer]].
+
# Click on the {{Menu|FluenceXL|Grid}} ribbon item (or the {{Menu|FluenceXL|Design Grid}} menu item in Excel 2003 and below). For more information about using this dialog, see [[Report Designer]].
 
# Move {{Code|Measures}} to columns, {{Code|Product}} to rows and {{Code|Time}} to headers.
 
# Move {{Code|Measures}} to columns, {{Code|Product}} to rows and {{Code|Time}} to headers.
 
# Click on the {{Code|Time}} hierarchy, then select {{Code|2004}}, the year we want to analyse.
 
# Click on the {{Code|Time}} hierarchy, then select {{Code|2004}}, the year we want to analyse.
Line 92: Line 115:
  
 
==Creating Named Sets==
 
==Creating Named Sets==
A named set is a Multidimensional Expressions (MDX) expression that returns a set of dimension members. Named sets can be created at cube level or within an application such as XLCubed. They can be created combining cube data, arithmetic operators, numbers and functions.
 
 
 
You create a named set from the Custom Calculation tab:
 
 
[[Image:NamedSet6.png|200px|centre]]
 
  
 +
A named set is a Multidimensional Expressions (MDX) expression that returns a set of dimension members. Named sets can be created at cube level or within an application such as FluenceXL. They can be created by combining cube data, arithmetic operators, numbers and functions.
  
[[Image:NamedSet5.png|20px|left]] Click Insert a new calculated set
+
Within the Manage Calculations dialog, click '''Insert a new calculated set''' ([[Image:NamedSet5.png|20px]] ).
  
 +
A new calculation will appear with two fields on the right:
 +
*'''Name'''
 +
*'''Expression''': The expression needs to be inside braces as below { } and separated by commas (see example below).
  
In this example I have created a named set, RacksAndStands, which is a grouping of Bike Racks and Bike Stands.
 
  
The expression needs to be inside parenthesis as below { } and separated by commas.
+
The screenshot below shows a  created a named set, RacksAndStands, which is a grouping of Bike Racks and Bike Stands. The expression is:
  
 
'''{[Product].[Product Model Categories].[Subcategory].&[26],[Product].[Product Model Categories].[Subcategory].&[27]}'''
 
'''{[Product].[Product Model Categories].[Subcategory].&[26],[Product].[Product Model Categories].[Subcategory].&[27]}'''
  
[[Image:NamedSet1.png|200px|centre]]
+
[[Image:NamedSet1.png|600px|centre]]
 
   
 
   
The next step is to include the named set in the report.
 
  
[[Image:NamedSet2.png|200px|centre]]
+
===Using Named Sets===
  
You must be editing the hierarchy/dimension that the named set is linked to in this example Product Model Categories.
+
To use a named set within a report, go to the [[Member Selector]] of  the hierarchy/dimension that the named set is linked to, in this example Product Model Categories. Under the Advanced tab, select the '''Member Set''' icon
 
[[Image:NamedSet5.png|20px|left]] Click on the Advanced tab and select Member Set
 
 
  
You should see your named set appearing as below – select it and click OK.
+
[[Image:NamedSet5.png|300px|centre]].  
  
 +
The named set will appear as below, select it and click OK.
  
[[Image:NamedSet3.png|200px|centre]]
+
[[Image:NamedSet3.png|300px|centre]]
  
  
Line 131: Line 148:
  
  
[[Image:NamedSet4.png|200px|centre]]
+
[[Image:NamedSet4.png|300px|centre]]
 +
 
 +
=== Dynamic sets ===
 +
New in [[Version 8.1]] you can flag a set as being dynamic, which means they will be calculated when the query is run. This is useful when the members in the set change based on the slice being analysed, e.g. Top 10 products, with the year changing in a slicer.
 +
 
 +
More information can be found here: http://sqlblog.com/blogs/mosha/archive/2007/08/25/mdx-in-katmai-dynamic-named-sets.aspx
 +
 
 +
== Show with Captions ==
 +
 
 +
New in v7.2 there is an option within Custom Calculations to switch from showing unique names to captions
 +
 
 +
[[Image:calc1.png|500px|centre]]
 +
 
 +
==Custom Scripts==
 +
 
 +
Custom scripts can run any piece of MDX script you need to alter your cube. There is a restriction in Analysis services that each command can only contain one MDX statement.
 +
 
 +
The most common use of these is to create [http://msdn.microsoft.com/en-us/library/ms145989.aspx Scope] assignments, for example:
 +
 
 +
[[Image:ScopeScript.png|600px|centre]]
 +
 
 +
==Importing and Exporting calculations==
 +
 
 +
From [[Version 8|FluenceXL v8.0]], you can import and export XML files containing the calculations in the current workbook.
  
 
==See Also==
 
==See Also==
 +
* [[Mdx:]] - Allows creating simple calculations using Excel references.
 
* [[Calculations Overview]]
 
* [[Calculations Overview]]
 
* [[Grid Reporting Overview]]
 
* [[Grid Reporting Overview]]
 +
* [[FluenceXL Excel Edition Troubleshooting#Error when editing calculated members based on calculated sets|Error when editing calculated members based on calculated sets]]
  
* Microsoft listing of MDX functions: [[www.msdn.microsoft.com/en-us/library/ms145970.aspx]]
+
* [http://msdn.microsoft.com/en-us/library/ms145970.aspx Microsoft listing of MDX functions]
 
+
* [http://www.e-tservice.com/Files/vba_functions_in_as2005.doc Listing of VBA functions supported in MDX]
* Listing of VBA functions supported in MDX:[[http://www.e-tservice.com/Files/vba_functions_in_as2005.doc]]
 
  
 
[[Category:OLAP Operations]]
 
[[Category:OLAP Operations]]

Latest revision as of 10:23, 29 July 2024

Not all OLAP environments are as rich as we, the analysts would like. These examples show how FluenceXL allows the power of OLAP to be simply used to improve our analyses.

For Fluence and Anaplan connections there is a list of supported MDX functions.

Creating Calculated Members

To create a custom calculated member, open the Manage Calculations dialog from the FluenceXL > Custom Calculations ribbon option.

Select the Insert a new calculated member toolbar button (NewCalculatedMember.png). This will create a new blank calculation from which you can fill in the following fields:

  • Name: The name for the new calculated member.
  • Parent hierarchy: The hierarchy the calculated member will belong to.
  • Parent member: The unique name of the parent member for the new calculation. If no member is specified, the calculated member will be created at the top level of the hierarchy.
  • Expression: The MDX expression for the calculated member. You can use the treeview on the left to drag and drop members into the expression.


All calculated members in the workbook appear on the left. Any calculation can be edited by selecting it in this control and then overwriting the fields on the right.

To delete a calculation, select the desired calculation and click the Delete the selected calculation toolbar button.


Example (based on the Bicycle Sales cube)

We will create new Gross Profit and Gross Profit Margin measures.

Start by creating a connection to the BicycleSales Demo Cube. This cube only has one measure, Value, but several different 'views' of the data, provided by the KeyFigures hierarchy.

To create the calculated measures:

  1. Open the Manage Calculations dialog (FluenceXL > Custom Calculations).
  2. To create the Gross Profit member, click the Insert a new calculated member toolbar button
  3. A new 'untitled' member will appear. Fill in the following details for the new member:
  4. Name Gross Profit
    Parent hierarchy KeyFigures
    Parent member [KeyFigures].[All]
    Expression [KeyFigures].[All].&[Revenue] - [KeyFigures].[All].&[Cost of Sales] - [KeyFigures].[All].&[Production Costs]
    Custom calculations dialog with the Gross Profit member
    The Gross Profit member


  5. Create a second calculated member for the Gross Profit Margin member, and fill in the following details. To enter the format string, Show advanced controls must be clicked:
  6. Name Gross Profit Margin
    Parent hierarchy KeyFigures
    Parent member [KeyFigures].[All]
    Expression [KeyFigures].[All].[Gross Profit] / [KeyFigures].[All].&[Revenue]
    Format string 0%
    Custom calculations dialog with the Gross Profit Margin member
    The Gross Profit Margin member


  7. We now have members in the KeyFigures hierarchy, but if we want to use them as normal measures, we need to create two more members in the Measures hierarchy:
  8. Name Gross Profit
    Parent hierarchy Measures
    Parent member Leave empty
    Expression ([KeyFigures].[All].[Gross Profit],[Measures].[Value])


    Name Gross Profit Margin
    Parent hierarchy Measures
    Parent member Leave empty
    Expression ([KeyFigures].[All].[Gross Profit Margin],[Measures].[Value])
    Format string 0%
  9. Click on OK to create the calculated members.

We can now see the new measures in context. Let's find badly performing product groups for 2004.

  1. Click on the FluenceXL > Grid ribbon item (or the FluenceXL > Design Grid menu item in Excel 2003 and below). For more information about using this dialog, see Report Designer.
  2. Move Measures to columns, Product to rows and Time to headers.
  3. Click on the Time hierarchy, then select 2004, the year we want to analyse.
  4. Click on the Measures hierarchy to select the Gross Profit and Gross Profit Margin measures.
  5. Click OK to insert the Grid.
  6. When we drill down on the Product hierarchy, we can see that Road S8000 is the failing product.

We could extend this report to use In-Cell Charts. See Visual Grids for Performance Analysis to continue.

Creating Named Sets

A named set is a Multidimensional Expressions (MDX) expression that returns a set of dimension members. Named sets can be created at cube level or within an application such as FluenceXL. They can be created by combining cube data, arithmetic operators, numbers and functions.

Within the Manage Calculations dialog, click Insert a new calculated set (NamedSet5.png ).

A new calculation will appear with two fields on the right:

  • Name
  • Expression: The expression needs to be inside braces as below { } and separated by commas (see example below).


The screenshot below shows a created a named set, RacksAndStands, which is a grouping of Bike Racks and Bike Stands. The expression is:

{[Product].[Product Model Categories].[Subcategory].&[26],[Product].[Product Model Categories].[Subcategory].&[27]}

NamedSet1.png


Using Named Sets

To use a named set within a report, go to the Member Selector of the hierarchy/dimension that the named set is linked to, in this example Product Model Categories. Under the Advanced tab, select the Member Set icon

NamedSet5.png

.

The named set will appear as below, select it and click OK.

NamedSet3.png


You can then select to include/exclude the named set in your report.

In this example the members of the named set will not appear in the report.


NamedSet4.png

Dynamic sets

New in Version 8.1 you can flag a set as being dynamic, which means they will be calculated when the query is run. This is useful when the members in the set change based on the slice being analysed, e.g. Top 10 products, with the year changing in a slicer.

More information can be found here: http://sqlblog.com/blogs/mosha/archive/2007/08/25/mdx-in-katmai-dynamic-named-sets.aspx

Show with Captions

New in v7.2 there is an option within Custom Calculations to switch from showing unique names to captions

Calc1.png

Custom Scripts

Custom scripts can run any piece of MDX script you need to alter your cube. There is a restriction in Analysis services that each command can only contain one MDX statement.

The most common use of these is to create Scope assignments, for example:

ScopeScript.png

Importing and Exporting calculations

From FluenceXL v8.0, you can import and export XML files containing the calculations in the current workbook.

See Also