CUBESETCOUNT Function

Excel Functions › Cube

Excel 2007+ Data Model / OLAP

The Excel CUBESETCOUNT function counts the items in a CUBESET — how many categories, how many active customers, how many months matched — one number, straight from the Data Model.


Quick answer: how many members are in the set stored in B2:
=CUBESETCOUNT(B2)
The argument is usually just a cell reference to a CUBESET formula.

Syntax

=CUBESETCOUNT(set)
ArgumentDescription
setRequiredA cell containing a CUBESET formula, or a CUBESET typed inline.

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

Inline form, counting all customers in one shot:

=CUBESETCOUNT(CUBESET("ThisWorkbookDataModel", "[Customers].[Name].children"))

Pair it with CUBERANKEDMEMBER loops to know when to stop, or report “12 active products” style headlines.

Try it: interactive demo

Live demo

Toggle which categories belong to the set and watch the count.

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 CUBESETCOUNT 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

Why does CUBESETCOUNT only take one argument?
The set already knows its connection — it was defined in the CUBESET. CUBESETCOUNT just counts what's inside.
Can it count filtered members, like customers with sales over $1,000?
Yes, if the set expression itself filters (MDX Filter() expressions). The counting is dumb; the set definition is where the logic lives.
CUBESETCOUNT vs COUNTA — when which?
COUNTA counts worksheet cells. CUBESETCOUNT counts members inside a Data Model set that never touches the grid. Different worlds.
It returns 0 — what's wrong?
The referenced cell probably isn't a CUBESET (or the set expression matched nothing). Check the set cell first.

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