Forum Discussion

MattScruggs's avatar
MattScruggs
Frequent Visitor
5 years ago
Solved

Filter if a Table if selected date falls between 2 date ranges

I have the following set up.  Tag       Start Date     End Date 1234 12/31/2009 1/21/2020 1235 3/8/2019 3/10/2019 1236 1/30/2019   1237 5/18/2008   1238 4/3/2020 10/5/2020 ...
  • AlB's avatar
    5 years ago

    MattScruggs 

    I'm posting here as well the response discussed by PM

    I filtered out the blanks on build date (visual filter).

     

    The updated, simplified code for the measure is:

    Show measure V3 = 
    VAR minPeriod_ = MIN ( Calendar[Date] )
    VAR maxPeriod_ = MAX ( Calendar[Date] )
    VAR currentStart_ = CALCULATE( SELECTEDVALUE ( Table1[ActualBuildDate] ), ALL('Calendar'))
    VAR currentEnd_ = CALCULATE( SELECTEDVALUE ( Table1[ActualDismantleDate]), ALL('Calendar'))
    RETURN
        IF (
            NOT (
                currentStart_ > maxPeriod_
                    || ( currentEnd_ < minPeriod_ && NOT ISBLANK ( currentEnd_ ) )
            ),
            1,
            0
        )

    1. If you place this measure in the table visual it should work. Do check that the results are as expected. However, you need to keep the measure in the visual. See it on page SCAFF.Monthly (2)

    2. However, taking the measure off the visual and placing it as visual filter as we had done earlier will not work because of the Calendar columns you are using in the slicer. In this case the rows shown will be the ones shown in point 1 except those for which ActualBuildDate falls outside the selected period in the slicers. This is because of the relationship between Calendar[Date] and Table1[ActualDismantleDate] See it on page SCAFF.Monthly (3)

     

    So if the solution on SCAFF.Monthly (2) is not good enough and you want the measure outside the visual, you have 2 options:

      a) Delete (or deactivate) the Calendar[Date] and Table1[ActualDismantleDate] relationship.

      b) Build an auxiliary date table that you'll use for the slicers and won't interfere with the visual. In this case the measure above will need to be adapted a bit

     

    Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.

    Cheers