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
Anonymous
Not applicable

Calculate if selected date is between two dates

Hi everyone!

 

I am struggling with a difficult problem. I have a fact table with 2 dates: Task Start Date and Task End Date. I have another dimension table (calendar table) with 2 inactive relationships between these 2 dates and calendar date. In calendar table I have information about Year and month.

 

How to calculate it in dax? I have tried with something using selectedvalue(calendar[year]), selectedvalue(calendar[month]) and combine it with these 2 dates, but it is incorrect. 1 should be inserted if calendar Year and calendar Month match to Year and Month these 2 dates. 

BS33_0-1654859884001.png

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Anonymous 

please use 

=
VAR MaxDate =
    MAX ( 'Calendar'[Date] )
VAR MinDate =
    MIN ( 'Calendar'[Date] )
RETURN
    SUMX (
        TableName,
        IF ( TableName[StartDate] <= MaxDate && TableName[EndDate] >= MinDate, 1 )
    )

View solution in original post

1 REPLY 1
tamerj1
Super User
Super User

Hi @Anonymous 

please use 

=
VAR MaxDate =
    MAX ( 'Calendar'[Date] )
VAR MinDate =
    MIN ( 'Calendar'[Date] )
RETURN
    SUMX (
        TableName,
        IF ( TableName[StartDate] <= MaxDate && TableName[EndDate] >= MinDate, 1 )
    )

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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.