Forum Discussion
Need help with filtering two dates using a single slicer in Power BI
- Anonymous1 year ago
Hi all,thanks for the quick reply, I'll add more.
Hi Anonymous ,
Regarding your question, I don't think there should be a relationship between the fact table and the time dimension table. You seem to have created a table-to-table relationship between the 'Date' column of the fact table and the time dimension table. This will result in only filtering the 'Date' column and not the 'StartDate' & 'EndDate' columns. My suggestion is to remove the relationship between the two tables.
The Table data is shown below:
Use the following DAX expression to create a measure
Measure = VAR _startDate = MIN('DateTable'[Date]) VAR _endDate = MAX('DateTable'[Date]) VAR _factTableDate = SELECTEDVALUE('Table'[Date]) VAR _factTableStartDate = SELECTEDVALUE('Table'[Start Date]) VAR _factTableEndDate = SELECTEDVALUE('Table'[End Date]) RETURN IF( (_factTableDate >= _startDate && _factTableDate <= _endDate) && (_factTableStartDate >= _startDate && _factTableStartDate <= _endDate) && (_factTableEndDate >= _startDate && _factTableEndDate <= _endDate), 1,BLANK() )Power BI automatically hides measure that result in 'Blank', which gives the correct result.
Turn off the 'Text wrap' option in the table visual
Move the mouse over the marker and the '<-||->' symbol will appear, drag it.
Final output
Best Regards
Hi Anonymous
You can't be using a related dates table for that as you'll be able to filter only by either the start or end date. You will need to create a measure for that.
Count by Time Period =
VAR StartDate =
MIN ( Dates[Date] )
VAR EndDate =
MAX ( Dates[Date] )
RETURN
COUNTROWS (
FILTER (
Contracts,
Contracts[Date Start] <= EndDate
&& Contracts[Date End] >= StartDate
)
)
Using the measure above, you can see below that contract code AA009Contract1 appears in 2018-01 to 2018-12 as its start and end dates are within these periods. Please see the attached sample pbix.