Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
JaviGolden
Frequent Visitor

is in Date range

I have a matrix that I'm trying to use values from a table named 'Programs'.   

IdNameCurrencyCodeStartDateEndDate
318Program Name 11USD7/2/202310/15/2024
397Program Name 66GBP10/10/202411/1/2024
376Program Name 29GBP7/25/202411/7/2024
103Program Name 97GBP1/24/20249/12/2024
489Program Name 51USD8/28/20249/25/2024


I want the Name column to be the first column in the matrix.   I have a slicer that select a data range.  ie 1/1/2024 - 6/3/2024.  I want any program that is active at any point within the date range to be included in the matrix.   Based on the dates 1/1/2024-6/30/2024, I should have Program Name 11 and Program Name 97 in the matrix.   

 

I created this measure to verify if the program was within the selected date range:

IsWithinDateRange =
VAR Date_Selected_Min = MIN(Dates[Date]) -- Minimum date from slicer
VAR Date_Selected_Max = MAX(Dates[Date]) -- Maximum date from slicer
VAR ProgramStartDate = SELECTEDVALUE(Programs[StartDate]) 
VAR ProgramEndDate = SELECTEDVALUE(Programs[EndDate])     
RETURN
    SWITCH (
        TRUE(),
        ProgramStartDate >= Date_Selected_Min && ProgramStartDate <= Date_Selected_Max, TRUE,
        ProgramEndDate >= Date_Selected_Min && ProgramEndDate <= Date_Selected_Max, TRUE,
        ProgramStartDate <= Date_Selected_Max && ProgramEndDate >= Date_Selected_Min, TRUE, -- Overlap case
        FALSE
    )
The measure returns TRUE or FALSE correctly, however, it doesn't work as a filter on the visual.   
 
How do I accomplish this?   Thanks!  
1 ACCEPTED SOLUTION
Bibiano_Geraldo
Super User
Super User

Hi @JaviGolden ,
I just made a little changes in your measure, instead of TRUE or FALSE, i'm using 1 to represent True, and 0 to represent False. here's the updated measure:

IsWithinDateRange = 
VAR Date_Selected_Min = MIN(Dates[Date]) -- Minimum date from slicer
VAR Date_Selected_Max = MAX(Dates[Date]) -- Maximum date from slicer
VAR ProgramStartDate = SELECTEDVALUE(Programs[StartDate]) 
VAR ProgramEndDate = SELECTEDVALUE(Programs[EndDate])     
RETURN
    SWITCH (
        TRUE(),
        ProgramStartDate >= Date_Selected_Min && ProgramStartDate <= Date_Selected_Max, 1,
        ProgramEndDate >= Date_Selected_Min && ProgramEndDate <= Date_Selected_Max, 1,
        ProgramStartDate <= Date_Selected_Max && ProgramEndDate >= Date_Selected_Min, 1, -- Overlap case
        0
    )

Add the Measure to the Filters Pane:

 

  • Select your matrix visual.
  • Open the Filters pane.
  • Drag the IsWithinDateRange measure to the Filters pane for the visual.
  • Set the filter condition to IsWithinDateRange = TRUE.

Bibiano_Geraldo_0-1734772089524.png

 

Now your Matrix or Table visual should look like this when your select the date range (1/1/2024 - 6/3/2024.)

 Bibiano_Geraldo_1-1734772234310.png

 

 

 

View solution in original post

5 REPLIES 5
Kedar_Pande
Super User
Super User

@JaviGolden 

You can try:

IsWithinDateRange =
VAR Date_Selected_Min = MIN(Dates[Date])
VAR Date_Selected_Max = MAX(Dates[Date])
VAR ProgramStartDate = SELECTEDVALUE(Programs[StartDate])
VAR ProgramEndDate = SELECTEDVALUE(Programs[EndDate])
RETURN
IF (
ProgramStartDate >= Date_Selected_Min && ProgramStartDate <= Date_Selected_Max
|| ProgramEndDate >= Date_Selected_Min && ProgramEndDate <= Date_Selected_Max
|| ProgramStartDate <= Date_Selected_Max && ProgramEndDate >= Date_Selected_Min,
1,
0
)

💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn

Idrissshatila
Super User
Super User

Hello @JaviGolden 

 

instead of true false, make it return 0,1 then use it to filter .



Did I answer your question? Mark my post as a solution! Appreciate your Kudos
Follow me on LinkedIn linkedIn
Vote for my Community Mobile App Idea

Proud to be a Super User!




Bibiano_Geraldo
Super User
Super User

Hi @JaviGolden ,
I just made a little changes in your measure, instead of TRUE or FALSE, i'm using 1 to represent True, and 0 to represent False. here's the updated measure:

IsWithinDateRange = 
VAR Date_Selected_Min = MIN(Dates[Date]) -- Minimum date from slicer
VAR Date_Selected_Max = MAX(Dates[Date]) -- Maximum date from slicer
VAR ProgramStartDate = SELECTEDVALUE(Programs[StartDate]) 
VAR ProgramEndDate = SELECTEDVALUE(Programs[EndDate])     
RETURN
    SWITCH (
        TRUE(),
        ProgramStartDate >= Date_Selected_Min && ProgramStartDate <= Date_Selected_Max, 1,
        ProgramEndDate >= Date_Selected_Min && ProgramEndDate <= Date_Selected_Max, 1,
        ProgramStartDate <= Date_Selected_Max && ProgramEndDate >= Date_Selected_Min, 1, -- Overlap case
        0
    )

Add the Measure to the Filters Pane:

 

  • Select your matrix visual.
  • Open the Filters pane.
  • Drag the IsWithinDateRange measure to the Filters pane for the visual.
  • Set the filter condition to IsWithinDateRange = TRUE.

Bibiano_Geraldo_0-1734772089524.png

 

Now your Matrix or Table visual should look like this when your select the date range (1/1/2024 - 6/3/2024.)

 Bibiano_Geraldo_1-1734772234310.png

 

 

 

danextian
Super User
Super User

Hi @JaviGolden 

Check if this works for you. The details are in the attached pbix.

danextian_0-1734766282216.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
lbendlin
Super User
Super User

[value]  in CALENDAR([startdate],[enddate])

 

or simpler

 

[value] in Dates[Date]

 

or a bit more fancy

 

countrows(intersect(calendar([startdate],[enddate]),Dates[Date]))>0

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.