CUBESET Function

Excel Functions › Cube

Excel 2007+ Data Model / OLAP

The Excel CUBESET function defines a set of members from a Data Model or OLAP cube — all categories, the top 5 customers, the months of one quarter — optionally sorted. Sets feed CUBERANKEDMEMBER (pull items out) and CUBESETCOUNT (count them).


Quick answer: all product categories, sorted descending by sales:
=CUBESET("ThisWorkbookDataModel", "[Products].[Category].children", "Categories", 2, "[Measures].[Total Sales]")

Syntax

=CUBESET(connection, set_expression, , [sort_order], [sort_by])
ArgumentDescription
connectionRequired"ThisWorkbookDataModel" for Power Pivot.
set_expressionRequiredMDX set, e.g. "[Products].[Category].children" or "{[A],[B]}" literals.
captionOptionalDisplay text for the cell.
sort_orderOptional0 keep order (default) · 1 asc by sort_by · 2 desc by sort_by · 3 alpha asc · 4 alpha desc · 5 natural asc · 6 natural desc.
sort_byOptionalMeasure to sort by, e.g. "[Measures].[Total Sales]" (required for orders 1-2).

What you need first: cube functions only work against a Power Pivot Data Model (or an external OLAP cube). Add your table to the model — check “Add this data to the Data Model” when inserting a PivotTable, or use the Power Pivot tab — then reference it with the connection name "ThisWorkbookDataModel" and MDX-style member strings like "[Measures].[Total Sales]" or "[Products].[Category].[Displays]".

How to use it

The top-N pattern: a sorted CUBESET in one cell, CUBERANKEDMEMBER pulling rank 1, 2, 3… below it:

B2: =CUBESET("ThisWorkbookDataModel", "[Customers].[Name].children", "By sales", 2, "[Measures].[Total Sales]")
B5: =CUBERANKEDMEMBER("ThisWorkbookDataModel", $B$2, ROW()-4) // copy down for rank 1, 2, 3…

Try it: interactive demo

Live demo

Choose a sort mode and see how the set expression changes.

Result:

Errors & common pitfalls

#NAME? — bad connection name. The first argument must exactly match a workbook connection; for the built-in Data Model it is "ThisWorkbookDataModel", quotes included.

#N/A — invalid member expression. Table, column, or item names in the MDX string don’t match the model. Check spelling and bracket every level: [Table].[Column].[Item].

“#GETTING_DATA” flashes in cells. Normal — Excel retrieves cube results asynchronously. It resolves when the query finishes.

Performance: hundreds of separate CUBEVALUE calls query the model one by one. Pull shared members into CUBEMEMBER cells once and reference those cells in your CUBEVALUEs.

Practice workbook

📊
Download the free CUBESET practice workbook
Every example on this page, ready to open in Excel — plus practice challenges with answers on a separate tab. No sign-up required.

Frequently asked questions

What does .children mean in a set expression?
[Products].[Category].children means “every member one level below” — all categories. It’s the workhorse of CUBESET expressions.
How do I build a top-10 list with CUBESET?
Sort the set descending by your measure (sort_order 2), then pull items 1-10 with CUBERANKEDMEMBER. The list re-ranks itself on every refresh.
The cell just shows my caption — where's the set?
That's how it works: the set lives in the cell invisibly. Point CUBERANKEDMEMBER or CUBESETCOUNT at the cell reference to use it.
Can I list specific members instead of .children?
Yes — brace literals: "{[Products].[Category].[Video],[Products].[Category].[Displays]}" defines exactly those two.

Master functions like this in one day

This page covers one function. Our Excel Formulas and Functions class covers the 30 that matter most — live, hands-on, taught by professionals in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.

See the Formulas & Functions Class

Related functions: CUBEVALUE · CUBEMEMBER · CUBESET · GETPIVOTDATA · GROUPBY