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
swestendorp
Helper I
Helper I

Calculate average duration of contracts over time

Good day, 

 

I am looking for help on the following. I would like to measure the average duration of contracts as a trend over time. I have a table with contract.employee_number, contract.startdate and contract.enddate and a date table with a relationship between contract.startdate and date table.date.

I would like to know, for example, what the average duration of contracts was in June '15. We have two types of situation to average: contracts that have ended and contracts that are ongoing in June 15. The first is easily covered, but how do I include the ongoing contracts if I want to make their duration startdate to June 15? And how do I add that to my average with the ended contracts?

 

Thanks a lot for your help!

 

Sifra

4 REPLIES 4
Greg_Deckler
Super User
Super User

Sample data please. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi all,

 

Sure!

 

So I have two tables

1. Crew contract table

2. Date table

 

Crew contract table looks as follows. For running contracts I use today's date as end date. 

 

EmployeeNoActual first dateActual end date
0044320-4-2015

4-9-2017

0045116-1-20174-9-2018
004604-6-20134-6-2016
0046615-5-20157-9-2015
0049211-5-201512-1-2008
005901-8-20184-9-2018

 

Data model looks as follows:

image.png

 

 

 

 

 

 

 

 

 

 

 

I need to determine what the average duration of ended and running contracts was at any given time.

What i would like to see is a time graph with year/month on X-axis and average duration of contracts on Y-axis. 

 

Thanks a lot!

hi,@swestendorp

    you may try to refer to this article: https://community.powerbi.com/t5/Quick-Measures-Gallery/Periodic-Billing/m-p/409365

 

If it is not your case, please share your expected output for data sample you provided it above.

 

Best Regards,

Lin

 

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

Hi Lin, 

 

Thanks a lot for reaching out, much appreciated. This is probably going waaay beyond my skill level, so my apologies in advance if I ask stupid questions. I think this could be a good solution to my issue, but I'm still struggling with the suggested measure. 

 

I've tried to adjust the measure to my situation:

 

Average duration = 
VAR tmpCalendar = ADDCOLUMNS('Date table',"Month1",MONTH([Date]),"Year",YEAR([Date]),"MonthYear",VALUE(YEAR([Date]) & FORMAT(MONTH([Date]),"0#")))
VAR tmpContract = ADDCOLUMNS('Crew overview table',"MonthYearBegin",VALUE(YEAR([Actual first date]) & FORMAT(MONTH([Actual first date]),"0#")),
                                      "MonthYearEnd",VALUE(YEAR([Actual end date]) & FORMAT(MONTH([Actual end date]),"0#")))
VAR tmpTable = 
SELECTCOLUMNS(
    FILTER(
        GENERATE(
            tmpContract,
            SUMMARIZE(tmpCalendar,[Year],[Month],[MonthYear])
        ),
        [MonthYear] >= [MonthYearBegin] &&
        [MonthYear] <= [MonthYearEnd]
    ),
    "Employee",[EmployeeNo],
    "Year",[Year],
    "Month1",[Month],
    "ContractDuration",[Contract duration]
)
RETURN AverageX(tmpTable,[ContractDuration])

I now tried to plot it against my date table, but I get an error 'cannot convert value " of type Text to type Number'.

 

What am I doing wrong? 

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.