Excel CUBE Functions XelPlus
Excel CUBE Functions XelPlus
CUBEVALUE Function.......................................................................................................................... 12
Conclusion .......................................................................................................................................... 18
CUBE FORMULAS in EXCEL
This manual is accompanying documentation for my online Power Pivot & DAX course on XelPlus.com/courses.
Please do not reproduce or transmit in any form without permission.
We (XelPlus e.U.) have taken every effort to ensure the accuracy of this manual. In case you discover any
discrepancies, please send us a quick email to [email protected].
About Leila Gharani
Leila Gharani is a Microsoft MVP and a bestselling online course instructor. She runs XelPlus.com, an Office
Productivity resource site to help people gain the knowledge they need so they can transform their data into
impressive reports and analyze these with ease. Leila also has a YouTube channel with a community of more than
1 million technology enthusiasts.
Her background is Masters in Economics, Economist, Consultant, Oracle HFM Accounting Systems Expert &
Project Manager (Oracle & SAP projects). Find out more here. Follow her on YouTube or Instagram.
CUBE FORMULAS in EXCEL
In a previous lecture we saw how to create a Data Model (Power Pivot) and took a preview of
how you can convert your Pivot Table into formulas.
This article will axpand on the two CUBE functions generated from this:
But first...
In the Excel context, to use CUBE FUNCTIONS, data need to be available either through a
connection to a SQL Server Analysis Services data source or through a Data Model (Power
Pivot).
As you may be aware, data residing in Power Pivot’s Data Model, is not directly visible in the
worksheet. That is, there are no cells available on the worksheet for traditional Excel formulas
to reference. Additionally, traditional Excel formulas can’t retrieve the Data from the Data
Model and that is where the CUBE functions come into play!
Cube functions allow Excel users to interact with the Power Pivot Data Model and access the
data without necessarily creating a Pivot Table. They allow you to create Excel report layouts
cell-by-cell.
As at the point of writing this article, Excel includes 7 CUBE functions as shown below. These 7
functions were added since Excel 2007.
But...
Why would you want to bother with these functions if you can create DAX formulas and
subsequently use the Power Pivot to create a Pivot table?
Creating Measures
Before going into CUBE functions, let us create a few DAX measures to use in the Pivot Tables.
In a previous lecture, we simply dragged and dropped the quantity field in a pivot table and
generated what we call implicit measures. In this article, we’ll use a DAX expression to create
explicit measures.
Total Quantity:=SUM(Sales[Quantity])
Let us now insert a Pivot Table based off the data model and put the [Total Quantity],
[Transactions] and [Distinct Product Count] in the Values box of the Pivot Report as follows:
Now, when we click Analyze →OLAP Tools →Convert to Formulas as illustrated above, we’ll
end up with the table as shown below, where Excel converts every cell into a formula -CUBE
formulas.
CUBEMEMBER Function
This formula extracts a member from a cube - either a measure name (such as Total Quantity)
or an element from a column in a table (such as ‘Bicycle Pumps’ from the Product table, in the
Product Name column).
It determines what part of the data cube your CUBEVALUE formula returns. This is the syntax:
• Connection -A text string of the name of the connection to the cube. In an Excel data
model, Excel automatically creates it, and will always be ThisWorkbookDataModel
• Member_expression -This is either a reference to a DAX measure or slices the data
cube through certain members
• Caption -A user-friendly name or alias used if the name of the measure or table field
is not in a user readable format
When a Power Pivot report is converted to formulas, the measure names and table fields are
converted into CUBEMEMBER() formulas.
In this example, if we take the Athletics product main category, we start by typing the formula
CUBEMEMBER and immediately after the opening parenthesis, when you type the double
quotations, you’ll get an intellisense of the data model name.
You can press the TAB key on the keyboard to complete the connection name and close the
double quotes.
After the separator, we then specify what field or measure we are targeting by explicitly
defining the source table in the data model, the source column and the field name. These are
also specified inside double quotation marks, where the targeted field name is specified by
joining the text strings with an ampersand sign, &.
You need to add a period/dot after each text string, which also gives the intellisense to select
the intended item.
So, the formula will look as follows:
To use this formula to reference the aggregations, we would point it to the ‘Measures’ table
(not an actual table, but a way to select available measures in the data model).
As you can see below, you only get to see the list of measures available in the data model:
Thus, the CUBEMEMBER formula equivalent for Total Quantity measure is:
TIP
CUBEVALUE Function
Once the table fields and measures have been defined, we then apply the CUBEVALUE function
to generate the corresponding summaries (aggregated values) from the data model.
The CUBEVALUE formula will calculate an aggregated value directly from the
data cube / data model based on parameters that are passed into the
formula, including cube members or slicer values.
• Connection -A text string of the name of the connection to the cube. In an Excel data
model, Excel automatically creates it, and will always be ThisWorkbookDataModel
• Member_expressions -text string(s) of a multidimensional expression (MDX) that
evaluates to a member or tuple within the cube
In our example, to return the Total Quantity aggregated value for ‘Communications’ product
category, we write the formula as shown below:
If the measure happens to be typed somewhere in a cell, we use the following syntax.
***the name of the measure should be typed exactly as in the Data Model
Though not necessary to nest a CUBEMEMBER formula within a CUBEVALUE one, the following
formula entered in cell C5 below still works:
=CUBEVALUE("ThisWorkbookDataModel",
CUBEMEMBER("ThisWorkbookDataModel", "[tblProduct].[MainCategory].[" &$B5 &"]"),
C$4)
For instance, in the illustration below we are slicing the Total Quantity by the Department
column in the Products table as well as the Transaction types from the Transaction Type table.
The CUBEVALUE is used to reference the various columns/fields to generate the aggregated
values at the intersection of the product department and the transaction type.
If you don’t see ‘Insert Slicer’ from the Insert tab, you can right click on the
ribbon and choose Customize Ribbon. On the window that appears, choose
Commands not in the ribbon.
To get the slicer name, right mouse click the slicer →Slicer Settings →the name will be
displayed as below.
Conclusion
When you load data to a Data Model (Power Pivot), you can use Pivot Tables to summarize it.
CUBE formulas provide you with the flexibility when you need custom layouts for your report
which you can’t achieve with the Pivot Tables.
This short article has focused only on CUBEMEMBER and CUBEVALUE functions. Click this
resource to learn more on the others we have not covered.