How to Create a Dynamic CUBESET for Multiple Period Ranges in Excel
Question details
The user needs to build a dynamic Excel CUBESET that filters data by region and a variable date range (start and end periods) defined by cell values.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Creating dynamic financial or performance reports in Excel using Data Models, MDX syntax, and cube functions to filter specific timeframes.
- Observed behavior
- The user requires the proper MDX syntax to pass start and end date cell references into a CUBESET expression while ensuring accurate chronological sorting.
Ensure your Excel workbook contains an active Data Model with accurately established relationships, and verify that your calendar table includes a chronological YearMonth field to prevent alphabetical sorting errors.
Build a Dynamic MDX Set Expression Using Cell References
Use the CUBESET function combined with the TEXT function to dynamically reference start and end dates from spreadsheet cells, effectively building an MDX range.
When filtering a CUBESET across a date range, you can construct an MDX expression that joins the start and end month members. By passing cell references into the TEXT function, users can update the report's date range dynamically without needing to alter the complex MDX formula manually.
Enter your desired start date in one cell (e.g., A1) and your end date in another cell (e.g., A2) in standard date format.
Write the CUBESET formula by referencing the Data Model and concatenating the cell values into the MDX string. For example: =CUBESET("ThisWorkbookDataModel", "EXISTS([Brandmaster].[Brand].children, ([State_Master].[State].[Maharashtra], {[Calendar].[Month].["&TEXT(A1,"mmm-yyyy")&"]:[Calendar].[Month].["&TEXT(A2,"mmm-yyyy")&"]}))", "Set", 2, "")
Ensure that the formatting syntax within your TEXT function (such as "mmm-yyyy") perfectly matches the naming convention used in your Data Model's Calendar table.

Use WPS Office for Powerful Data Analysis and Pivot Tables
While advanced MDX Data Models are native to Microsoft Excel, WPS Office provides a robust, free, and lightweight alternative for handling large datasets, standard pivot tables, and complex functions with a highly familiar user interface.
- 1. Open Your Dataset: Launch WPS Spreadsheets and open your dataset.
- 2. Insert Pivot Table: Navigate to the 'Insert' tab on the ribbon and click 'Pivot Table'.
- 3. Analyze Data: Select your data range, place the Pivot Table on a new worksheet, and drag your date fields into the Filters or Rows areas to group periods dynamically.

Frequently Asked Questions
Why does my CUBESET sort months alphabetically instead of chronologically?
If your month names are stored as text (e.g., 'October', 'November'), the application sorts them alphabetically by default. To fix this, you must use a YearMonth index or a chronological date key in your Sort By argument.
Can I use multiple measures in the Sort By argument of CUBESET?
No, the Sort By expression typically requires a single member, measure, or month index that resolves to exactly one value. Passing a range or a dynamic set of months to the Sort By argument can cause formula errors.
What happens if the generated member names do not match the data model?
If the output of your TEXT function does not exactly match the naming convention in your data model (for example, generating 'Oct-2024' when the model expects '10-2024'), the CUBESET function will fail to locate the data and return an error or an empty set.




