Skip to content

Provide multi_stage measure a way to ignore one or more filter #9811

@michofwood

Description

@michofwood

I have been banging my head against a wall trying to do something that's easily done in MDX and DAX. i.e. calculating a "Calculated measure" with a removed filter, or let say by unfiltering a complete "cube" or dimension in MDX/DAX.
DAX has the All(Dimension) https://learn.microsoft.com/en-us/dax/all-function-dax , i forgot how to do in MDX, it's been too long ago,
The requirement: Calculate a ratio between "All of something" and a thing, providing that the thing may be filtered.
As example, in the above example I had a long chat with the Cube AI, it's about knowing the percentage of city_sales/country_sales. (https://cube-js.slack.com/archives/C04NYBJP7RQ/p1752690359948029)

The multi_stage with Tesseract answer a fair part of the solution and works great without filters on cities, but when applying a filter on cities, then the multi_stage calculation inherit all of the cube filter, including the city one.
I understand that that could be a valid use case, where when filtering cities, then the denominator could only be on the total of the selected ones.

But, the case where the denominator stays all cities is also a valid one.

CubeAI suggested to use filters_to_ignore which does not exists but seems to me that would be a wonderfull thing short term to add.

**I would suggest to provide both, cube and cube.dimension to ignore, maybe with a "" or whatever for those who have a star-schema. Something like:

    - filters_to_ignore:
      percent_of_total.product  # Single dimension to ignore
      dim_product.*             # Entire cube filters to ignore

This is CubeAi explaining me the solution

Creating a Multi-Stage Measure That Ignores Product Dimension Filters
You're looking to create a multi-stage measure that ignores filters applied to the product dimension, while still calculating totals across all products. This is a perfect use case for controlling filter propagation in multi-stage measures.
How It Works

  1. The new filters_to_ignore array specifies dimensions whose filters should be ignored during the multi-stage calculation
  2. When a filter is applied to the product dimension, the country_revenue measure will still calculate its total across all products
  3. This ensures that your percentage calculations remain consistent regardless of product filtering
country_revenue: {
      multi_stage: true,
      sql: `{revenue}`,
      format: `currency`,
      type: `sum`,
      group_by: [
        `country`
      ],
      filters_to_ignore: [
        'percent_of_total.product'
      ]
    },

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions