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

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

Reply
bombom
Helper I
Helper I

Power BI average between different dates

Hello!

I want to calculate average time between to dates. The data looks like this:

 

StepDatetime
214.11.2022 13:02:56
414.11.2022 13:05:15
214.11.2022 13:11:23
414.11.2022 13:13:38
214.11.2022 13:24:03
414.11.2022 13:26:21
215.11.2022 12:16:58
415.11.2022 12:19:28

 

I need to get an average time between all the steps number 4 and stpes number 2.

 

14.11.2022 13:05:15 - 14.11.2022 13:02:56 = 00:02:19

14.11.2022 13:13:38 - 14.11.2022 13:11:23 = 00:02:15

14.11.2022 13:26:21 - 14.11.2022 13:24:03 = 00:02:18

15.11.2022 12:19:28 - 15.11.2022 12:16:58 = 00:02:30

 

The average between all four equals to 00:02:20

 

When I use formula measure = CALCULATE(SUM(Logging[CreatedAt]),Logging[Step] = 4) - CALCULATE(SUM(Logging[CreatedAt]),Logging[Step] = 2) it calculates the total of all four rows.

 

The result of the formula above 30.12.1899 0:09:22

 

(by the way, how to get rid of this strange date result 30.12.1899?)

 

If I use formula measure = AVERAGEX(Logging, CALCULATETABLE(VALUES(Logging[CreatedAt]), FILTER(Logging, Logging[Step] = 4)) - CALCULATETABLE(VALUES(Logging[CreatedAt]), FILTER(Logging, Logging[Step] = 4))) it delivers nothing.

 

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

Hi, @bombom 

For your needs, you'll need to convert the difference to "seconds", take the average and convert the result back to time format.

Please try measure formula like:

EndAt = 
IF (
    MAX ( Logging[Step] ) = 2,
    CALCULATE (
        MIN ( Logging[CreatedAt] ),
        FILTER ( ALL ( Logging ), Logging[CreatedAt] > MAX ( Logging[CreatedAt] ) )
    ),
    BLANK ()
)
diff(second) = DATEDIFF(MAX(Logging[CreatedAt]),[EndAt],SECOND)
Average = AVERAGEX(Logging,[diff(second)])
Result1 = 
IF (
    [Average] = BLANK (),
    BLANK (),
    TIME ( 0, 0, FLOOR ( 'Souktion1'[Average], 1 ) )
)

If the total result is 30.12.1899 0:09:22, you just need to change the format of your measure.

veasonfmsft_0-1670220033856.png

Result:

veasonfmsft_1-1670220283849.png

 

Reference:

TIME 

FLOOR 

 

Best Regards,
Community Support Team _ Eason

 

View solution in original post

2 REPLIES 2
v-easonf-msft
Community Support
Community Support

Hi, @bombom 

For your needs, you'll need to convert the difference to "seconds", take the average and convert the result back to time format.

Please try measure formula like:

EndAt = 
IF (
    MAX ( Logging[Step] ) = 2,
    CALCULATE (
        MIN ( Logging[CreatedAt] ),
        FILTER ( ALL ( Logging ), Logging[CreatedAt] > MAX ( Logging[CreatedAt] ) )
    ),
    BLANK ()
)
diff(second) = DATEDIFF(MAX(Logging[CreatedAt]),[EndAt],SECOND)
Average = AVERAGEX(Logging,[diff(second)])
Result1 = 
IF (
    [Average] = BLANK (),
    BLANK (),
    TIME ( 0, 0, FLOOR ( 'Souktion1'[Average], 1 ) )
)

If the total result is 30.12.1899 0:09:22, you just need to change the format of your measure.

veasonfmsft_0-1670220033856.png

Result:

veasonfmsft_1-1670220283849.png

 

Reference:

TIME 

FLOOR 

 

Best Regards,
Community Support Team _ Eason

 

amitchandak
Super User
Super User

@bombom , Try a measure like

 

AVERAGEX(Table,
var _max = maxx(filter(Table, Table[Datetime] < earlier([Datetime]) && [Step] =2),[Datetime])
return
if([Step] =4,datediff(_max,[Datetime],second) ,blank())
)

 

 

or

 

time(0,0,0) + AVERAGEX(Table,
var _max = maxx(filter(Table, Table[Datetime] < earlier([Datetime]) && [Step] =2),[Datetime])
return
if([Step] =4,datediff(_max,[Datetime],second) ,blank())
)/(3600*24)

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.