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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
NumeroENAP
Helper III
Helper III

AVERAGE DATEDIFF between two dates (two events and one column)

Hi, 

 

I want a dynamic measure to be able to calculate the AVERAGE difference between two dates of a same column. The trick is that the calculation is between two status, which are "First contact" and "Contacted". The second trick is that there could be more that one subscribtion for the same ID (so you need to pick the last date per status).

 

Here's my draft :
 

CALCULATE(

AVERAGEX(
    TABLE, 
          DATEDIFF(
               CALCULATE(LASTDATE(TABLE[Date]) , TABLE[Status]="First contact") , 
               CALCULATE(LASTDATE(TABLE[Date]) , TABLE[Status]="Contacted") , 
               DAY))
FILTER(
   CALCULATE(LASTDATE(TABLE[Date]) , TABLE[Status]="First contact") < CALCULATE(LASTDATE(TABLE[Date]) ,
   TABLE[Status]="Contacted")
)

 

But, of course, the result is blank...

 

Here's my data sample.

 

IndexIDNameStatusDate
12222200Name1First contact2020-10-01
22222201Name2First contact2020-10-02
32222202Name3First contact2020-10-03
42222200Name1Contacted2020-10-12
52222201Name2Contacted2020-10-12
62222202Name3Contacted2020-10-12
72222203Name4Contacted2020-10-13
82222200Name1Subscribed2020-11-24
92222200Name2Subscribed2020-11-25
102222200Name3Subscribed2020-11-26

 

Can you help me?

 

Thank you

1 REPLY 1
lbendlin
Super User
Super User

Use variables to construct your logic step by step

 

- create a table variable that holds all unique IDs

- add columns that hold the latest "First Contact" date for each ID and the latest "Contacted" date for the same ID

- eliminate rows where either of these fields are missing

- calculate the averagex of the date diff for the remaining rows.

 

Let me know if you would like help with the DAX code.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors