0% found this document useful (0 votes)
96 views

Excel CUBE Functions XelPlus

Un puff de chocolate con chocolate y pan de los pueblos y así

Uploaded by

kralex.ayalaj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views

Excel CUBE Functions XelPlus

Un puff de chocolate con chocolate y pan de los pueblos y así

Uploaded by

kralex.ayalaj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Table of Contents

Cube Formulas in Excel ...................................................................................................................... 5

What are Cube Formulas? .................................................................................................................... 5

When to use Cube Formulas................................................................................................................. 7

Getting started with Cube Formulas..................................................................................................... 7

CUBEMEMBER Function ....................................................................................................................... 9

CUBEVALUE Function.......................................................................................................................... 12

How to Combine Cubemember with Cubevalue ................................................................................ 14

How to Add Multiple Filters ................................................................................................................ 15

How to Add Slicers to Cube Formulas................................................................................................. 15

How to Refresh Cube Formulas .......................................................................................................... 17

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

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:

CUBEMEMBER and CUBEVALUE.

But first...

What are Cube Formulas?


DATA CUBES are multidimensional sets of data that provide a means to swiftly summarize
information from the raw data source. Data in a cube is already grouped in hierarchies, and
calculated measures are saved in the cube.

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!

5|Page Copyright © 2021 Leila Gharani


CUBE FORMULAS in EXCEL

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.

We’ll cover CUBEMEMBER and CUBEVALUE functions in this article.

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?

6|Page Copyright © 2021 Leila Gharani


CUBE FORMULAS in EXCEL

When to use Cube Formulas


The main advantage of using CUBE functions is that you have more control over the report
layout and presentation as opposed to when using a normal Pivot Table where you’re limited to
a predefined Pivot structure.
Other reasons why you may want to use CUBE functions include:
1. There is no loss of functionality when designing charts. With normal Pivot charts, you
cannot edit the ranges once inserted.
2. With CUBE functions, you can easily add custom spacing (that is, you can insert
rows/column in between, something you can’t do on normal Pivots), with precise
grouping.

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])

Distinct Customer Count:=DISTINCTCOUNT(tblCustomer[CustNum])

Distinct Product Count:=DISTINCTCOUNT(tblProduct[ProductCode])

Getting started with Cube Formulas


As earlier noted, the easiest way to kick-start your Cube functions journey is by creating a Pivot
Table that uses the Data Model as its Data Source.

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:

7|Page Copyright © 2021 Leila Gharani


CUBE FORMULAS in EXCEL

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.

8|Page Copyright © 2021 Leila Gharani


CUBE FORMULAS in EXCEL

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:

CUBEMEMBER(connection, member_expression, [caption])

• 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.

From the above screenshot, we have the formulas as illustrated here:

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.

9|Page Copyright © 2021 Leila Gharani


CUBE FORMULAS in EXCEL

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:

The GRAND TOTAL equivalent of the above formula would be:

10 | P a g e Copyright © 2021 Leila Gharani


CUBE FORMULAS in EXCEL

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:

You can access the members of the selected field/column by typing a

dot/period after the .[All]

TIP

11 | P a g e Copyright © 2021 Leila Gharani


CUBE FORMULAS in EXCEL

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.

Here is the syntax:

CUBEVALUE(connection, [member_expression1], [member_expression2], …)

• 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:

12 | P a g e Copyright © 2021 Leila Gharani


CUBE FORMULAS in EXCEL

CUBEVALUE syntax variations


Grand Total for a given Measure:
To use CUBEVALUE function to return the total quantity sold, we can write this formula:

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

Aggregate Value for a specified member, e.g. ‘Audio’ product category


You can explicitly use the formula below to return the value for the ‘Audio’ product category for
the Total Quantity measure.

=CUBEVALUE("ThisWorkbookDataModel", "[Measures].[Total Quantity]",


"[tblProduct].[MainCategory].[" & G12 & "]")

13 | P a g e Copyright © 2021 Leila Gharani


CUBE FORMULAS in EXCEL

How to Combine Cubemember with Cubevalue


As seen above, the CUBEMEMBER formulas return the filters or column elements and measures
that can be used as arguments in a CUBEVALUE formula.

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)

14 | P a g e Copyright © 2021 Leila Gharani


CUBE FORMULAS in EXCEL

How to Add Multiple Filters


Just like in a Pivot Table, you can have different filters in play in your CUBE-driven report.

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.

How to Add Slicers to Cube Formulas


Now, we want to restructure the above report such that the Transaction Type is coming from a
slicer selection.
First, we’ll go to the Inset tab and select Slicer. From the ensuing window, click Data Model tab
→click Open, and from the next window, tick the column that you wish to use for the slicer. In
this case the ‘Transaction Type Name’

15 | P a g e Copyright © 2021 Leila Gharani


CUBE FORMULAS in EXCEL

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.

In cell C5 below, we type the following formula:

CUBEVALUE("ThisWorkbookDataModel", $C$4, $B5, Slicer_TransTypeName)

...where Slicer_TransTypeName is the name of the slicer inserted above.

16 | P a g e Copyright © 2021 Leila Gharani


CUBE FORMULAS in EXCEL

To get the slicer name, right mouse click the slicer →Slicer Settings →the name will be
displayed as below.

How to Refresh Cube Formulas


CUBE formulas are refreshed by refreshing the Data Model. That is, you can press Refresh All
either from the Data tab in Excel or the Home tab of the Power Pivot window.

17 | P a g e Copyright © 2021 Leila Gharani


CUBE FORMULAS in EXCEL

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.

18 | P a g e Copyright © 2021 Leila Gharani

You might also like