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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.