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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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.