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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
DavidWaters
Helper I
Helper I

Calculate how many contracts are live for any given month

Hi, I have got a difficult calculation which involves returning how many contracts are live for a given calendar table month, based on the contract start and expiry date.

 

StartExpiry
03/02/202124/03/2021
19/02/202108/09/2021
05/03/202102/06/2021
06/10/202111/04/2022
07/10/202103/04/2022
01/10/202109/01/2022
27/11/202105/03/2022

 

I want to use the Calendar table month to then return the number of live contracts at these months:

 

Jan-210 
Feb-2122 started in Feb
Mar-2131 started in Mar, the other 2 still live from Feb
Apr-2121 expired in March so drops off
May-212Just 2 still live
Jun-212Just 2 still live
Jul-2111 expires in June so drops off
Aug-211Just 1 still live
Sep-211Just 1 still live
Oct-2133 new but 1 drops off a expired in Sept
Nov-2141 new plus the other 3 still live
Dec-214all 4 still live

 

I tried below measures but they don't work so I think I need another approach but have not resolved so if anyone can offer some wisdom that would be great!

 

# Open Contracts =
VAR MinDate = MIN( DataTable[StartDate] )
VAR MaxDate = MIN( DataTable[StartDate] )
RETURN COUNTROWS(
FILTER(
DataTable,
DataTable[StartDate] <= MaxDate
&& DataTable[ExpiryDate]>= MinDate
)
)

 

 

rolling12 =

CALCULATE(

[# Open Contracts],

DATESINPERIOD( 'Calendar Table'[Date], max('Calendar Table'[Date]), -12, MONTH )

)

1 ACCEPTED SOLUTION
DavidWaters
Helper I
Helper I

Here is the solution, I eventually cobbled it together 
 
new calc = CALCULATE (
COUNTROWS (
FILTER (
Premium,
(
Premium[InceptionDate] IN VALUES ( 'Calendar Table'[Date] )
|| Premium[InceptionDate] < MIN ( 'Calendar Table'[Date] )
&& (
Premium[ExpiryDate] IN VALUES ( 'Calendar Table'[Date] )
|| ISBLANK ( Premium[ExpiryDate] )
|| Premium[ExpiryDate]> MAX ( 'Calendar Table'[Date] )
)
)
&& Premium[1] = 1
)
),
CROSSFILTER ( Premium[InceptionDate], 'Calendar Table'[Date], NONE )

View solution in original post

3 REPLIES 3
DavidWaters
Helper I
Helper I

Here is the solution, I eventually cobbled it together 
 
new calc = CALCULATE (
COUNTROWS (
FILTER (
Premium,
(
Premium[InceptionDate] IN VALUES ( 'Calendar Table'[Date] )
|| Premium[InceptionDate] < MIN ( 'Calendar Table'[Date] )
&& (
Premium[ExpiryDate] IN VALUES ( 'Calendar Table'[Date] )
|| ISBLANK ( Premium[ExpiryDate] )
|| Premium[ExpiryDate]> MAX ( 'Calendar Table'[Date] )
)
)
&& Premium[1] = 1
)
),
CROSSFILTER ( Premium[InceptionDate], 'Calendar Table'[Date], NONE )

What is Premium[1] supposed to represent here?

Hi @DavidWaters 

 

Glad you have solved it by yourself! You can accpet your reply as solution to close this thread. This can also make it easier to be found by other users who have similar problems. 

 

Best Regards,
Community Support Team _ Jing

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors