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
antbob
Frequent Visitor

Count active contracts which are within date slicer range based on separate start/end date columns

Looking for some help with a measure I am working on and can't seem to figure out.  

 

I have a contract table with contractid, startdate, enddate columns.  I need to count contracts that were/are active at any point during a date range specificed on the reports date range slicer.

 

I have tried approached including datesbetween, IF statements, and Filters, but am stuck.  Any help is much appreciated.

 

 

contractid

Startdate

Enddate

123456

11/01/2017

11/31/2018

112233

12/15/2017

03/03/2018

144523

01/01/2018

01/01/2019

 

So If the date range slicer was set for 11/05/2017 - 01/05/2018 the count would show 2

1 ACCEPTED SOLUTION
v-frfei-msft
Community Support
Community Support

Hi @antbob ,

 

Here we can create a measure as below to get the excepted result we need.

 

Measure =
CALCULATE (
COUNTROWS ( Table1 ),
FILTER ( Table1, Table1[Startdate] > MIN ( 'Table'[Date] ) )
)

Capture.PNG
Please find the pbix as attached.

 

Regards,
Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

5 REPLIES 5
Waxy
Frequent Visitor

In addition to having the number of contracts for the date range, how to show the list of contract available?

Hi,

My suggestion would be to convert the 3 column dataset into a 2 column dataset - ContractID and Date.  Then build a Calendar Table with a relationship.  That way when one selects a data range (built from the Calendar Table) in a slicer, only those ContractID's would show up.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-frfei-msft
Community Support
Community Support

Hi @antbob ,

 

Here we can create a measure as below to get the excepted result we need.

 

Measure =
CALCULATE (
COUNTROWS ( Table1 ),
FILTER ( Table1, Table1[Startdate] > MIN ( 'Table'[Date] ) )
)

Capture.PNG
Please find the pbix as attached.

 

Regards,
Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Thanks @v-frfei-msft,

 

This is certainly closer then I was able to get, and spawned a light bulb moment of understanding.  The end goal is to be able to say how many contracts were active say in the last 3 months, or even the last 6 months given variable length contracts

 

Here is what I ended up with, which I have yet to fully validate, but a few quick spot checks seemed accurate

 

Measure = CALCULATE ( 
COUNTROWS(Table1 ),
FILTER( Table1, ( Table1[StartDate] >= MIN ( Table[Date] ) && Table1[StartDate] < MAX ( Table[Date] ) )||( Table1[EndDate] > MIN ( Table[Date]) && Table1[EndDate] <= MAX ( Table[Date] ) )||( Table1[StartDate] < MIN ( Table[Date]) && Table1[EndDate] > MAX ( Table[Date] ) ) ) )

 

Anonymous
Not applicable

here is my suggestion to tackle this :

 

first Make a new date table.

 

DateTable = Calendar(Minx(table1,Table1[Date]),Now()) 

Now add a new calculated column:

 

DateSlicer = CALCULATE(
    COUNTROWS(contractid),
    FILTER(Table1,
        DateTable[Date] >= [startdate] &&
        DateTable[Date] <= [Enddate])

 

Hope this  will help.

 

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.