Forum Discussion
Filter table if dates range is overlapping other dates range in another table
Greetings.
I have a Table 'C' what contains two columns 'colStart' and 'colEnd'. It's a Date Range.
What I need is a slider that allows to select a dates range and filter 'C' table showing only those rows that have any kind of overlapping with it.
To create the slider I just created a table using CALENDAR:
Calendar = CALENDAR(FIRSTDATE(C[colStart])|LASTDATE(C[colEnd]))
Thanks to https://community.powerbi.com/t5/Desktop/Calculate-days-from-filter-overlapping-date-ranges/td-p/216857 I already have a Measure that identifies that, but I can't filter the table using it:
Measure:
in_range =
var startD = FIRSTDATE(ALLSELECTED('CALENDAR'[Date]))
var endD = LASTDATE(ALLSELECTED('CALENDAR'[Date]))
var finiv = MAX(C[colStart])
var ffinv = MAX(C[colEnd])
return
(finiv >= startD && finiv <= endD) ||
(ffinv >= startD && ffinv <= endD) ||
(finiv < startD && ffinv > endD)Measure result:
I want to filter 'C' table, showing only where in_range is True. This is because I have related tables with 'C' that also need be filtered.
Hope you can help me. Tell me if you don't understand something. I have a test .pbix file but i don't know if it's possible to upload here.
Thanks!
Hi Anonymous
It is impossible to create a new table physically (click on "New Table") and make it change with slicer.
You could use a table visual and make the table visual change with the slicer.
1.Create a calendar date table
calendar = CALENDAR(MIN(Table1[colStart]),MAX(Table1[colEnd]))
Edit relationship with "calendar" table and data table based on 'calendar' [Date] to [colStart] and 'calendar' [Date] to [colEnd]
2. create measures
create measures in the 'calendar' table
min = MIN('calendar'[Date]) max = MAX('calendar'[Date])create measures in the data table
flag = IF(MAX(Table1[colStart])<=[max]&&MAX(Table1[colEnd])>=[min],1,0)
3. add 'calendar' [Date] to the slicer, then add 'Table1'[flag] to the Visual Level filter and select "show items when value is 1"
Best regards
Maggie
9 Replies
- LivioLanzoSolution Sage
The table can be filtered like this:
VAR mnDte = MIN( 'Calendar'[Date] )
VAR mxDte = MAX( 'Calendar'[Date] )
RETURN
CALCULATETABLE(
DateRanges,
DateRanges[colEnd] >= mnDte,
DateRanges[colStart] <= mxDte
)- AnonymousNot applicable
Thanks LivioLanzo but I have created new table with that formula and does not work. It never changes when updating slicer.
It's like MIN( 'Calendar'[Date] ) is returning the lowest date in the table when it should returns the lowest filtered date by slicer. Same with MAX. (my assumptions)
Other suggestion?
Thanks
- AnonymousNot applicable
In other post, I see that v-ljerr-msft said:
"Not like measures, calculate columns/tables are computed during database processing(e.g. data refresh) and then stored in the model, they do not response to user selections on the report.
So it is not possible to create a calculate column/table can change dynamically with user selections on the report. (...)"
Now I'm totally lost...
How could I achieve the goal then?
- v-juanli-msftCommunity Support
Hi Anonymous
It is impossible to create a new table physically (click on "New Table") and make it change with slicer.
You could use a table visual and make the table visual change with the slicer.
1.Create a calendar date table
calendar = CALENDAR(MIN(Table1[colStart]),MAX(Table1[colEnd]))
Edit relationship with "calendar" table and data table based on 'calendar' [Date] to [colStart] and 'calendar' [Date] to [colEnd]
2. create measures
create measures in the 'calendar' table
min = MIN('calendar'[Date]) max = MAX('calendar'[Date])create measures in the data table
flag = IF(MAX(Table1[colStart])<=[max]&&MAX(Table1[colEnd])>=[min],1,0)
3. add 'calendar' [Date] to the slicer, then add 'Table1'[flag] to the Visual Level filter and select "show items when value is 1"
Best regards
Maggie