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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
pfarias
Advocate I
Advocate I

Return the average of the difference of dates from a list (DAX)

I need to return the average of the difference between a list of dates. Only one date may appear in this list, returning zero as the difference, but it may also appear two, or three, or more dates.

How could I do that using DAX?

 

06/01/2021
07/01/2021
15/01/2021

 

The expected result, based on this example, would be 4.5 days. Considering that the first day must be considered as BLANK and not as zero, so that the average is disregarded.

The proposal in using the measure that is being created is to return the average number of days of customer return, where each date is the purchase date.

 

I wrote a measure in which I got the expected result, but it performs very poorly.

 

AVERAGEX (
    SUMMARIZE ( fSales, [customerID], [dateSale], [storeID] ),
    VAR _LastDate =
        CALCULATE ( MAX ( fSales[dateSale] ), fSales[dateSale] < EARLIER ( [dateSale] ) )
    VAR _Diff =
        DATEDIFF ( _LastDate, [dateSale], DAY )
    RETURN
        _Diff
)

 

 

2 REPLIES 2
amitchandak
Super User
Super User

@pfarias , A new measure

 

AverageX( Table,
var _max = maxx(filter(Table, [Date] < earlier([Date]) ), [Date])
return
if(isblank(_max) , blank(), datediff(_max, [Date], [Day]))
)

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

Thanks for your response. But it's doesn't work well.

 

I changed AverageX for AddColumns, to be able to visualize the result in the table.

customerIDsaleDateMeasure
9998812/06/20211
9998812/07/20211
9998812/15/20211

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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
Top Kudoed Authors