Cube function

CUBESET function

Defines a set of members (such as all reps, sorted by revenue) from a Data Model or cube, for use by CUBERANKEDMEMBER, CUBESETCOUNT or CUBEVALUE.

Available in Excel 2007 and later for Windows, Microsoft 365, Excel for the web (with Data Model or supported OLAP sources); Excel for Mac 2016+ for the Data Model

Excel 2007 and laterNot in Google Sheets

Syntax

CUBESET(connection, set_expression, [caption], [sort_order], [sort_by])
ArgumentWhat it means
connectionRequiredThe cube connection name, e.g. "ThisWorkbookDataModel".
set_expressionRequiredAn MDX expression that returns a set, e.g. "[Sales].[Rep].[All].Children", or a cell range of CUBEMEMBER cells.
captionOptionalText to show in the cell. Without it the cell looks empty.
sort_orderOptional0 keep the cube's order (default), 1 ascending by sort_by, 2 descending by sort_by, 3 alphabetical A-Z, 4 alphabetical Z-A, 5 natural ascending, 6 natural descending.
sort_byOptionalThe measure to sort by when sort_order is 1 or 2, e.g. "[Measures].[Total Revenue]".

Returns: A set object. The cell displays caption; other cube functions use the set behind it.

How CUBESET works

CUBESET gathers a group of members into one cell - all reps, all products in a category, the months of a year - and can sort them by a measure on the server. On its own it only shows a caption, but it powers dynamic reports: CUBERANKEDMEMBER picks the 1st, 2nd and 3rd items out of the set to build a top-N list, CUBESETCOUNT counts how many items it has, and CUBEVALUE can total a set as a whole.

The examples use the sample Sales table (Rep, Region, Product, Units, Revenue) loaded into the workbook's Data Model - for example by ticking Add this data to the Data Model when inserting a PivotTable, or by loading it from Power Query. The Data Model's connection is always called ThisWorkbookDataModel, and a measure named Total Revenue (=SUM(Sales[Revenue])) was added with Power Pivot or the Add Measure command.

The set expression is MDX. .Children of the All member lists every item of a column; you can also list members explicitly in braces or use functions like TopCount. Sorting by a measure (sort_order 1 or 2 with sort_by) is done by the cube, which is why top-N reports built this way stay fast even on millions of rows.

Examples

1All reps, best first

A1fx=CUBESET("ThisWorkbookDataModel", "[Sales].[Rep].[All].Children", "Reps by revenue", 2, "[Measures].[Total Revenue]")
A
1Reps by revenue

Result: Reps by revenue

The set holds the four reps sorted by Total Revenue, highest first (Ana, Dev, Ben, Chloe). The cell shows only the caption.

2Products alphabetically

A2fx=CUBESET("ThisWorkbookDataModel", "[Sales].[Product].[All].Children", "Products", 3)
A
1
2Products

Result: Products

Sort order 3 sorts by name A-Z; no measure is needed. The set contains Laptop, Monitor and Mouse.

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 13 KB

Common errors and how to fix them

ErrorWhy it happensFix
#N/AThe set expression is invalid or returns no members.Check the MDX names, for example by converting a pivot to formulas.
#VALUE!sort_by was left out with sort order 1 or 2, or the set is too large.Add the measure to sort by, or narrow the set.
#GETTING_DATAData is still loading.Wait a moment.

Tips

  • Always give a caption, or the cell will look empty and someone may delete it.
  • =CUBEVALUE("ThisWorkbookDataModel", "[Measures].[Total Revenue]", A2) with a set in A2 returns the total over all members of the set.

Google Sheets

No OLAP cube functions; use pivot tables, QUERY, or Connected Sheets for BigQuery data.

CUBESET in other languages

In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.

LanguageFunction name
DanishKUBESÆT
DutchKUBUSSET
FinnishKUUTIOJOUKKO
FrenchJEUCUBE
GermanCUBEMENGE
HungarianKOCKA.HALM
ItalianSET.CUBO
Norwegian (Bokmål)KUBESETT
PolishZESTAW.MODUŁÓW
Portuguese (Brazil)CONJUNTOCUBO
Portuguese (Portugal)CONJUNTOCUBO
RussianКУБМНОЖ
SpanishCONJUNTOCUBO
SwedishKUBUPPSÄTTNING
TurkishKÜPKÜMESİ