Forum Discussion
Single date picker with calender
- 10 months ago
You do not need to create a relationship between the date table and your join/left date columns for this scenario to work in Power BI. Creating a relationship only on Join Date will filter the table directly, but you can use a measure-based approach for flexible filtering without relying on relationships to make your left date also work.
Solution: Measure-Based Filtering Without Relationships
Create a calendar (date) table in your model and mark it as a Date Table.
Do NOT create a model relationship between your calendar table and your student table on Join Date or Left Date.
Create a DAX measure that, for each record, checks if the selected date from the slicer falls between Join Date and Left Date (or if Left Date is blank, treats as still active).
Use the single date picker slicer from the calendar table for user selection.
Apply this measure as a visual-level filter (= 1) on your table/visuals.
Sample Measure:
ActiveTillSelectedDate = VAR _selDate = SELECTEDVALUE('Calendar'[Date]) RETURN IF( 'StudentData'[Join Date] <= _selDate && (ISBLANK('StudentData'[Left Date]) || 'StudentData'[Left Date] >= _selDate), 1, 0 )Filter visuals with ActiveTillSelectedDate = 1.
This way, selecting a date from the slicer will show all students who joined on or before that date and are either still active or left after that date, regardless of direct relationships in your data model.
Hi All,
Does the same work with Direct Query? I have a requirement on selection of a specific date, it needs to be passed in a SQL Server function and get the updated data back.