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

DAX: Count values based on date range from another table

I am really struggling with this one - hoping some one can help me.

 

In short I want to count usage (engagements) based on a contract period. I have three key tables:

Table 1: Contracts

- accountid

- contractid

- contract_start_date

- contract_end_date

 

Table 2: Accounts

- accountid

 

Table 3: Engagements

- accountid

- engagementid

- engagement_date

 

They are joined as such:

Contracts-Accounts-Engagements
accountid*:1accountid1:*accountid

 

Problem:

I want to create a measure on the contracts table that will count engagements that took place ('engagement_date') during the contract period ('contract_start_date' & 'contract_end_date').


I feel like this shouldn't be that difficult but I can't seem to get this to work. I have tried a number of things, using CountRows and Filter but often the results seem to come back incomplete. 

Does anyone have any suggestions on this. Thanks so much for help in advance! 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Try like

sumx(summarize(Accounts, Accounts[accountid], "_1", countx(filter(Engagements, Engagements[engagement_date] >= min(Contracts[contract_start_date]) && Engagements[engagement_date] <= min(Contracts[contract_start_date]) ),Engagements[engagementid])),[_1])

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

This worked perfectly, thank you so much Amit! You have saved me a huge headache!! Really appreciate the quick reply as well. This forum is the best 🏆

amitchandak
Super User
Super User

@Anonymous , Try like

sumx(summarize(Accounts, Accounts[accountid], "_1", countx(filter(Engagements, Engagements[engagement_date] >= min(Contracts[contract_start_date]) && Engagements[engagement_date] <= min(Contracts[contract_start_date]) ),Engagements[engagementid])),[_1])

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.