apache / superset

Apache Superset is a Data Visualization and Data Exploration Platform
https://superset.apache.org/
Apache License 2.0
61.85k stars 13.55k forks source link

Cross-filter between two tables and its dimensions #30345

Open Thoufiqkhan opened 2 hours ago

Thoufiqkhan commented 2 hours ago

Bug description

We are unable to control cross-filtering between two dimensions in two different charts. While cross-filtering is enabled for both charts, not all dimensions should be cross-filterable. In Apache Superset, all dimensions are clickable and will affect the tables where cross-filtering is enabled.

For example, in the screenshot, the "Provider Snapshot" and "Top 10 Codes by Provider" charts have cross-filtering enabled. I want to allow cross-filtering only when clicking on the "Full Name" dimension. Currently, clicking on "Provider Specialty" also causes cross-filtering in the second table, which should not occur.

How to reproduce the bug

To reproduce this bug, follow these steps:

-Click on dimensions other than the intended one.

You will notice that the second chart is loading due to cross-filtering, which is not the desired behavior.

Screenshots/recordings

Cross-filter SS

Superset version

3.1.3

Python version

3.9

Node version

16

Browser

Chrome

Additional context

No response

Checklist

dosubot[bot] commented 2 hours ago

To control cross-filtering between two dimensions in different charts in Apache Superset and ensure that only specific dimensions, like "Full Name," trigger cross-filtering, you can use the cross-filtering configuration available in the Superset dashboard utilities.

Here is an example of how you can configure cross-filtering to enable it only for the "Full Name" dimension:

import { getCrossFiltersConfiguration } from 'src/dashboard/util/crossFilters';
import { FeatureFlag, isFeatureEnabled } from '@superset-ui/core';

const dashboardLayout = {}; // Your dashboard layout configuration
const metadata = {
  chart_configuration: {
    1: { // Replace with your chart ID
      crossFilters: {
        scope: {
          charts: [1], // Specify the chart IDs
          columns: ['Full Name'], // Specify the dimensions that should trigger cross-filtering
        },
      },
    },
  },
  global_chart_configuration: {
    scope: {
      charts: [1], // Specify the chart IDs
      columns: ['Full Name'], // Specify the dimensions that should trigger cross-filtering
    },
  },
};
const charts = {}; // Your charts state

if (isFeatureEnabled(FeatureFlag.DashboardCrossFilters)) {
  const crossFiltersConfig = getCrossFiltersConfiguration(dashboardLayout, metadata, charts);
  console.log(crossFiltersConfig);
}

In this example, the getCrossFiltersConfiguration function is used to specify that only the "Full Name" dimension should trigger cross-filtering. The metadata object defines the charts and columns that are included in the cross-filtering scope. The dashboardLayout and charts objects represent your dashboard layout and charts state, respectively. The isFeatureEnabled function checks if the cross-filtering feature is enabled [1].

Additionally, you might find these similar discussions helpful:

  1. Cross filter in bar chart by x-axis field, not by dimension [2].
  2. Superset Dashboard Cross Filtering on Selected Columns [3].

To continue talking to Dosu, mention @dosu.