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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
jgpbi
Helper I
Helper I

Show only data if it is between 2 dates stored in 2 different collumns.

I have a source based on contracts. I have a column for the 'Contract Begin Date' and a column for the 'Contract Expire Date'

 

What I want to be able to do is return records that are active which would mean their start date is before today and then end date is after today. 

 

I have tried the following but it still returns every date or more likely is doing nothing.

 

IsActive = IF(SELECTEDVALUE('CONTRACTS'[Contract Begin Date]) <= Today() && SELECTEDVALUE('CONTRACTS'[Contract Expire Date]) >= Today(), Yes, Yes)
 
Anythoughts on how to get this to work?
1 ACCEPTED SOLUTION

Figured that out on my own. Needed to format as DATE(2099,01,01).

 

IsActiveMeasure =
VAR CurrentDate = TODAY()
RETURN
IF(
MAX('CONTRACTS'[Contract Begin Date]) <= CurrentDate &&
MAX('CONTRACTS'[Contract Expire Date]) >= CurrentDate &&
MAX('CONTRACTS'[Contract Expire Date]) <>DATE(2099,01,01),
1, 0
)

View solution in original post

3 REPLIES 3
rohit1991
Super User
Super User

Hi @jgpbi ,

Your DAX formula isn't filtering properly because SELECTEDVALUE() only works for a single selected row in a visual. Use a measure or a calculated column instead.

 

Solution 1: Create a Calculated Column (Recommended for Filters):

This adds "Yes" for active contracts and "No" for expired or future contracts. You can now filter your visuals to show only "Yes".

 

IsActive = 
IF(
    'CONTRACTS'[Contract Begin Date] <= TODAY() && 
    'CONTRACTS'[Contract Expire Date] >= TODAY(), 
    "Yes", "No")

 

 

Solution 2: Use a Measure (For Dynamic Filtering in Visuals)

 

IsActiveMeasure = 
VAR CurrentDate = TODAY()
RETURN 
IF(
    MAX('CONTRACTS'[Contract Begin Date]) <= CurrentDate && 
    MAX('CONTRACTS'[Contract Expire Date]) >= CurrentDate, 
    1, 0
)

 

Apply this measure as a visual-level filter with IsActiveMeasure = 1.

"The goal is to turn data into information, and information into insight." – Carly Fiorina

Need Power BI help? Connect on LinkedIn.

 

 

Thank you, I figured out how to do it as an added column but I like your use as a measure better. 

 

Is there a way to filter out a specfic date, currently all contracts with no real end date have a date of 01/01/2099. But if I add the follwing logic to your code it isn't picking it up even though looking at the table it is stored exactly as 01/01/2099.

 

IsActiveMeasure =
VAR CurrentDate = TODAY()
RETURN
IF(
MAX('CONTRACTS'[Contract Begin Date]) <= CurrentDate &&
MAX('CONTRACTS'[Contract Expire Date]) >= CurrentDate &&
MAX('CONTRACTS'[Contract Expire Date]) <> 01/01/2099,
1, 0
)

 

Is there a way to match a specfic date?

Figured that out on my own. Needed to format as DATE(2099,01,01).

 

IsActiveMeasure =
VAR CurrentDate = TODAY()
RETURN
IF(
MAX('CONTRACTS'[Contract Begin Date]) <= CurrentDate &&
MAX('CONTRACTS'[Contract Expire Date]) >= CurrentDate &&
MAX('CONTRACTS'[Contract Expire Date]) <>DATE(2099,01,01),
1, 0
)

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.