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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
condo
Frequent Visitor

Need help writing calculate formula using dates between two tables

I am trying to write a formula in the date table to calculate the number of ID's where the Date (on the date table) is between two dates on the ID table. See below for example: (Trying to create formula for highlighted column)

 

Data Table.JPG

 

ID Table.JPG

 
 
 

What I am trying to write a formula to tell me: DISTINCTCOUNT OF ID's if DATE (date table) is >=[Date Opened] AND DATE (Date table) is <=[Date Closed].

 

Any help would be greatly appreciated!

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

Hello @condo 

I think this will work for you.  It is a calculated column on the Date table.

Count of IDS = 
CALCULATE(
    DISTINCTCOUNT( 'ID Table'[ID] ),
    FILTER ( 
        'ID Table',
        'ID Table'[Date Opened] <= 'Date Table'[Date] && 
        'ID Table'[Date Closed] >= 'Date Table'[Date] )
    )

DateCount.jpg

 

 

View solution in original post

2 REPLIES 2
jdbuchanan71
Super User
Super User

Hello @condo 

I think this will work for you.  It is a calculated column on the Date table.

Count of IDS = 
CALCULATE(
    DISTINCTCOUNT( 'ID Table'[ID] ),
    FILTER ( 
        'ID Table',
        'ID Table'[Date Opened] <= 'Date Table'[Date] && 
        'ID Table'[Date Closed] >= 'Date Table'[Date] )
    )

DateCount.jpg

 

 

That did the trick- thanks!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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