Cube function

CUBESETCOUNT function

Counts the number of items in a set created by CUBESET.

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

CUBESETCOUNT(set)
ArgumentWhat it means
setRequiredA reference to a cell containing a CUBESET formula, or a CUBESET expression.

Returns: A whole number: how many members the set contains.

How CUBESETCOUNT works

CUBESETCOUNT tells you how many members are in a set - how many reps, products or customers a CUBESET returned. It is mostly used to make top-N or full-list reports adapt to the data: you can check whether a rank exists before asking CUBERANKEDMEMBER for it, or show a heading such as "4 reps".

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. In the examples, A1 holds =CUBESET("ThisWorkbookDataModel", "[Sales].[Rep].[All].Children", "Reps by revenue", 2, "[Measures].[Total Revenue]") and A2 holds the products set.

Examples

1How many reps?

B1fx=CUBESETCOUNT(A1)
AB
1Reps by revenue4
2Products

Result: 4

The rep set in A1 contains Ana, Ben, Chloe and Dev.

2How many products?

B2fx=CUBESETCOUNT(A2)
AB
1Reps by revenue
2Products3

Result: 3

The product set in A2 has Laptop, Monitor and Mouse.

3Hide ranks that do not exist

B3fx=IF(4 <= CUBESETCOUNT($A$1), CUBERANKEDMEMBER("ThisWorkbookDataModel", $A$1, 4), "")
AB
1Reps by revenue
2Products
3Chloe

Result: Chloe

The set has four reps, so rank 4 exists and the lowest earner, Chloe, is shown. In a row asking for rank 5 the same check returns empty text instead of an error.

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

Common errors and how to fix them

ErrorWhy it happensFix
#VALUE!The reference does not point to a CUBESET cell.Reference the cell with the CUBESET formula.
#GETTING_DATAThe set is still loading.Wait a moment.

Tips

  • The cell with the set itself shows only its caption - CUBESETCOUNT is the easiest way to check the set has loaded the members you expect.

Google Sheets

No OLAP cube functions; count rows of a QUERY or FILTER result with ROWS instead.

CUBESETCOUNT 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.ANTAL
DutchKUBUSSETAANTAL
FinnishKUUTIOJOUKKOJENMÄÄRÄ
FrenchNBJEUCUBE
GermanCUBEMENGENANZAHL
HungarianKOCKA.HALM.DB
ItalianCONTA.SET.CUBO
Norwegian (Bokmål)KUBESETTANTALL
PolishLICZNIK.MODUŁÓW.ZESTAWU
Portuguese (Brazil)CONTAGEMCONJUNTOCUBO
Portuguese (Portugal)CONTARCONJUNTOCUBO
RussianКУБЧИСЛОЭЛМНОЖ
SpanishRECUENTOCONJUNTOCUBO
SwedishKUBUPPSÄTTNINGANTAL
TurkishKÜPKÜMESAYISI