|
| 1 | +--- |
| 2 | +title: Cross-view filtering |
| 3 | +description: "Enable cross-view filtering in the DAX API to build dashboards that span multiple views in Power BI." |
| 4 | +--- |
| 5 | + |
| 6 | +By default, the [DAX API][ref-dax-api] exposes each [view][ref-views] as a |
| 7 | +separate perspective in [Power BI][ref-powerbi]. Visualizations from different |
| 8 | +views can't share the same filters, and a single report can't combine measures |
| 9 | +and dimensions across views. |
| 10 | + |
| 11 | +Cross-view filtering removes this limitation, letting you build dashboards |
| 12 | +that span multiple views and apply filters consistently across visualizations. |
| 13 | +It is supported in both [Live connection](#live-connection-mode) and |
| 14 | +[DirectQuery](#directquery-mode) modes. |
| 15 | + |
| 16 | +To use cross-view filters such as slicers, you must enable single-perspective mode |
| 17 | +in the DAX API. To enable single-perspective mode in the DAX API, |
| 18 | +set the `CUBEJS_DAX_SINGLE_PERSPECTIVE` environment variable to `true`. |
| 19 | + |
| 20 | +In single-perspective mode, all views are exposed as part of a single perspective. |
| 21 | +This allows you to use a single connection and show visualizations from different |
| 22 | +views on the same dashboard. |
| 23 | + |
| 24 | +<Warning> |
| 25 | + |
| 26 | +Single-perspective mode changes the way views are exposed by the DAX API. |
| 27 | +Because of that, it is not backwards-compatible with dashboards created before |
| 28 | +enabling this environment variable. |
| 29 | + |
| 30 | +</Warning> |
| 31 | + |
| 32 | +## Live connection mode |
| 33 | + |
| 34 | +In Live connection mode, cross-view filters work automatically, provided that |
| 35 | +the following two conditions are met: |
| 36 | + |
| 37 | +- The column used in the filter must be present in every view that the |
| 38 | +cross-filter has to be applied to, and named exactly the same in each view. |
| 39 | +- The column in all such views must resolve to the same cube member. |
| 40 | + |
| 41 | +For example, if views `orders_view` and `users_view` both expose a column named |
| 42 | +`address_country` pointing to the `country.country` cube member, cross-filtering |
| 43 | +will be applied across these views. |
| 44 | + |
| 45 | +If the `address_country` column in `orders_view` points to `orders.country` |
| 46 | +while the `address_country` column in `users_view` points to `users.country`, |
| 47 | +cross-filtering will not be applied, because the columns resolve to different |
| 48 | +cube members. |
| 49 | + |
| 50 | +Likewise, if `orders_view` exposes an `address_country` column pointing to |
| 51 | +`country.country` and `users_view` exposes a `country` column also pointing to |
| 52 | +`country.country`, cross-filtering will not be applied, because the column |
| 53 | +names differ between the views. |
| 54 | + |
| 55 | +## DirectQuery mode |
| 56 | + |
| 57 | +In DirectQuery mode, cross-view filters require the same two conditions as in |
| 58 | +[Live connection mode](#live-connection-mode): the filter column must be |
| 59 | +present in every view with the exact same name, and it must resolve to the |
| 60 | +same cube member across those views. |
| 61 | + |
| 62 | +In addition, you must manually configure relationships between tables in Power |
| 63 | +BI so that filters propagate across views: |
| 64 | + |
| 65 | +- Open **Model view** in the left sidebar. |
| 66 | +- On the right, open the **Data** sidebar, then the **Model** tab. |
| 67 | +- Right-click **Relationships** and choose **New relationship**. |
| 68 | +- In the **Properties** sidebar, select a table and a column. |
| 69 | +- For cardinality, choose **Many to many (\*:\*)**. Ignore the warning. |
| 70 | +- Select another table with the same column. |
| 71 | +- For cross-filter direction, select **Both**. |
| 72 | +- Click **Apply changes**. |
| 73 | + |
| 74 | +Once the relationship is configured correctly, cross-view filters will work in |
| 75 | +DirectQuery mode. |
| 76 | + |
| 77 | +The steps above describe configuring a relationship between two tables. When |
| 78 | +many views need to be cross-filtered, the best practice is to create a single |
| 79 | +view in the Cube data model that includes all the columns from the views that |
| 80 | +need to be cross-filtered, and then create relationships between this large |
| 81 | +view and each of the other views. This keeps the relationship graph in Power |
| 82 | +BI simple and avoids configuring pairwise relationships between every |
| 83 | +combination of views. |
| 84 | + |
| 85 | + |
| 86 | +[ref-dax-api]: /reference/core-data-apis/dax-api |
| 87 | +[ref-views]: /docs/data-modeling/views |
| 88 | +[ref-powerbi]: /admin/connect-to-data/visualization-tools/powerbi |
0 commit comments