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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Count date by contract expiration

I would like to understand how to count the number of active "contracts" whose information is based on maturity data and look at the 12-month average. Print for you to check, please help.

contratcs.png

1 ACCEPTED SOLUTION
andre
Memorable Member
Memorable Member

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]))

 

View solution in original post

5 REPLIES 5
v-alq-msft
Community Support
Community Support

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:

d1.png

 

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.

d2.png

 

d3.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Anonymous
Not 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.

MateusBueno94_0-1595940127004.png

 

amitchandak
Super User
Super User

@Anonymous ,The information you have provided is not making the problem clear to me. Can you please explain with an example.
But in case a contract done last 1 month is active, you can try, Join the contract date with

 

Active = CALCULATE(count(Table[contractid]),filter(date,date[date] <=maxx(date,date[date])))
Active = CALCULATE(count(Table[contractid]),filter(date,date[date] <=max(Sales[contractOn])))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-YTD-LYTD-Week-Over-Week/m-p/1051626#M184


Appreciate your Kudos.

 


Appreciate your Kudos.

Anonymous
Not applicable

Friend,

MateusBueno94_0-1595939963938.png

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.

andre
Memorable Member
Memorable Member

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]))

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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