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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.