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
sunnyleungthf
New Member

Count no of record with date range within a period

I think i need help on solving the problem, it seems not that complex but i just cannot think of how to make it.

 

I got a table containing records of contracts with contract start date and contract end date. Together with a date table, i would like to show in a bar chart the no. of active contracts in each month. Whether i should use measure to make it or need to create a table to handle this?

 

Thanks~~

1 ACCEPTED SOLUTION
dearwatson
Responsive Resident
Responsive Resident

So you will need a date to filter on... in this example I created a Calendar table with Calendar = CALENDARAUTO()

 

No need for any relation ships - you will use the calendar to act as an unrelated parameter.. its just to get a date to check against.

 

Then it is just one simple measure:

Active Contracts = CALCULATE(Contracts[Contracts],FILTER(Contracts,(Contracts[Contract Start]<=LASTDATE('Calendar'[Date])&&[Contract End]>=FIRSTDATE('Calendar'[Date]))))

 

The legendary Chris Campbell posted this solution on the legendary powerpivotpro.com blog a while back:

https://powerpivotpro.com/2013/04/counting-active-rows-in-a-time-period-guest-post-from-chris-campbe...

 

Capture.PNG

 

Cheers

Greg Nash

"The commonality between science and art is in trying to see profoundly - to develop strategies of seeing and showing." - Edward Tufte

View solution in original post

1 REPLY 1
dearwatson
Responsive Resident
Responsive Resident

So you will need a date to filter on... in this example I created a Calendar table with Calendar = CALENDARAUTO()

 

No need for any relation ships - you will use the calendar to act as an unrelated parameter.. its just to get a date to check against.

 

Then it is just one simple measure:

Active Contracts = CALCULATE(Contracts[Contracts],FILTER(Contracts,(Contracts[Contract Start]<=LASTDATE('Calendar'[Date])&&[Contract End]>=FIRSTDATE('Calendar'[Date]))))

 

The legendary Chris Campbell posted this solution on the legendary powerpivotpro.com blog a while back:

https://powerpivotpro.com/2013/04/counting-active-rows-in-a-time-period-guest-post-from-chris-campbe...

 

Capture.PNG

 

Cheers

Greg Nash

"The commonality between science and art is in trying to see profoundly - to develop strategies of seeing and showing." - Edward Tufte

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.