Forum Discussion
Count date by contract expiration
- 6 years ago
if you have a Contract table and Calendar table then you count number of Active contracts you can use something like this
Count of Active Contracts = countrows(calculatetable(all(Contract), Contract(StartDate)<SelectedValue(Calendar[date]) && Contract[MaturityDate}>SelectedValue(Calendar[date]))
Hi, Anonymous
Based on your description, I assume that you want to count number of active contracts whose start date is earlier than the selected date and the end date is later than the selected date. And then you can average based on these corresponding contracts. I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
Calendar(a calculated table):
Calendar = CALENDARAUTO()
There is no relationship between two tables. You may create two measures as below.
Count =
var tab =
ADDCOLUMNS(
'Table',
"flag",
IF(
ISFILTERED('Calendar'[Date]),
IF(
HASONEVALUE('Calendar'[Date]),
IF(
[Start Date]<=SELECTEDVALUE('Calendar'[Date])&&
SELECTEDVALUE('Calendar'[Date])<=[End Date],
1,0
),
1
),
1
)
)
return
COUNTROWS(
FILTER(
tab,
[flag]=1
)
)
Avg =
var tab =
ADDCOLUMNS(
'Table',
"flag",
IF(
ISFILTERED('Calendar'[Date]),
IF(
HASONEVALUE('Calendar'[Date]),
IF(
[Start Date]<=SELECTEDVALUE('Calendar'[Date])&&
SELECTEDVALUE('Calendar'[Date])<=[End Date],
1,0
),
1
),
1
)
)
return
AVERAGEX(
FILTER(
tab,
[flag]=1
),
[Value]
)
Finally you need to use the 'Date' column from 'Calendar' table to filter the result.
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Anonymous6 years agoNot applicable
It would be that example. I need to know per day / month, the contracts that are active based on their expiration date. My base has a contract since 2015, so I wanted to make an average of the last 12 months from the date shown on the chart or table.