How to handle multiple date columns with a single month filter in Apache Superset (Power BI USERELATIONSHIP use case) #36846
Replies: 1 comment
-
|
Hi @sreekanthpamujula9-byte! I'm Dosu and I’m helping the superset team. Superset doesn't natively support the Power BI USERELATIONSHIP pattern—there's no built-in way for a single dashboard time filter to control multiple metrics, each using a different date column, within the same chart or dataset. Only one temporal filter can be active per chart/dataset at a time, and there's no concept of active/inactive relationships between a date dimension and multiple fact table columns [source]. However, you can approximate this behavior using Jinja templating in virtual datasets or custom SQL. Superset provides the Example for PostgreSQL: Suppose your fact table is -- Enquiry metric
SELECT COUNT(*) AS enquiry_count
FROM leads
WHERE 1=1
{% set tf = get_time_filter('enquiry_date', remove_filter=True) %}
{% if tf.from_expr %} AND enquiry_date >= {{ tf.from_expr }} {% endif %}
{% if tf.to_expr %} AND enquiry_date < {{ tf.to_expr }} {% endif %}
-- Test drive metric
SELECT COUNT(*) AS test_drive_count
FROM leads
WHERE 1=1
{% set tf = get_time_filter('test_drive_date', remove_filter=True) %}
{% if tf.from_expr %} AND test_drive_date >= {{ tf.from_expr }} {% endif %}
{% if tf.to_expr %} AND test_drive_date < {{ tf.to_expr }} {% endif %}
-- Repeat for other metrics/columnsEach metric can be a separate chart, or you can UNION them for a summary table. The key is that each query block uses How to set up:
Limitations:
Alternative: References:
Let me know if you want a more detailed SQL example or guidance on the unpivot/view approach! To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Background
We are migrating reports from Power BI to Apache Superset.
In Power BI, we use a single Date dimension table with multiple relationships to a fact table that contains multiple date columns, such as:
Only one relationship (with enquiry_date) is active.
Other relationships are inactive and are activated at query time using the
USERELATIONSHIP()DAX function.Current behavior in Power BI
When a user selects a specific month (for example, December of the current year) from a single date slicer:
enquiry_datetest_drive_dateconversion_datebooking_dateAll metrics respond correctly to the same month selection, even though only one relationship is active.
Problem in Apache Superset
In Apache Superset:
USERELATIONSHIP()functionBecause of this, we are unable to reproduce the same behavior where:
Question
How should this type of requirement be handled in Apache Superset?
Specifically:
We are using PostgreSQL as the backend database.
Beta Was this translation helpful? Give feedback.
All reactions