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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Milan_TBC
Frequent Visitor

Average Customer Return Time

Hi,

I want to calculate the average return time of my customers over time. 
I have a table with general data such as Cust_ID, and order_date per order. 
Right now i have general calculations based on first_order and last_order, however this doesn't cover all averages, since some customers have 10+ orders. 

 

Is there a way to calculate the average time between orders? Using the regular DATE commands (DATEDIFF, DATESBETWEEN, etc,), i run into problems since most of them only accept two dates, not more. 

 

Thanks in advance!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Manal_Edd ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want.

1. Create two measures as below

Datediff = 
VAR _selcust =
    SELECTEDVALUE ( 'Table'[lead_customer_id] )
VAR _seldate =
    SELECTEDVALUE ( 'Table'[closed_at] )
VAR _predate =
    CALCULATE (
        MAX ( 'Table'[closed_at] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[lead_customer_id] = _selcust
                && 'Table'[closed_at] < _seldate
        )
    )
RETURN
    DATEDIFF ( _predate, _seldate, DAY )
average_orderTime = 
VAR _selcustid =
    SELECTEDVALUE ( 'Table'[lead_customer_id] )
VAR _count =
    CALCULATE (
        COUNT ( 'Table'[lead_customer_id] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[lead_customer_id] = _selcustid )
    )
VAR _sum =
    SUMX (
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[lead_customer_id] = _selcustid ),
        [Datediff]
    )
RETURN
    IF (
        ISBLANK ( [Datediff] ),
        0,
        IF ( _count = 1, _sum, ROUND ( DIVIDE ( _sum, _count - 1 ), 0 ) )
    )

2. Create a table visual 

yingyinr_1-1667812425964.png

 

If the above one can't help you get the desired result, please provide more sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

View solution in original post

6 REPLIES 6
Milan_TBC
Frequent Visitor

Customer Return.png

 

The following table is an indication for what is needed, where the yellow values are what i'm looking for!

 

@amitchandak Right now your solution does not seem to work, i recieve syntax errors, mainly "< earlier({order date]) )" does not seem to function correctly.

 

Looking forward to any other solutions, Thanks in advance!

Addendum;

 

average_orderTime also has to be yellow, this value is not calculated right now!

Anonymous
Not applicable

Hi @Manal_Edd ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want.

1. Create two measures as below

Datediff = 
VAR _selcust =
    SELECTEDVALUE ( 'Table'[lead_customer_id] )
VAR _seldate =
    SELECTEDVALUE ( 'Table'[closed_at] )
VAR _predate =
    CALCULATE (
        MAX ( 'Table'[closed_at] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[lead_customer_id] = _selcust
                && 'Table'[closed_at] < _seldate
        )
    )
RETURN
    DATEDIFF ( _predate, _seldate, DAY )
average_orderTime = 
VAR _selcustid =
    SELECTEDVALUE ( 'Table'[lead_customer_id] )
VAR _count =
    CALCULATE (
        COUNT ( 'Table'[lead_customer_id] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[lead_customer_id] = _selcustid )
    )
VAR _sum =
    SUMX (
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[lead_customer_id] = _selcustid ),
        [Datediff]
    )
RETURN
    IF (
        ISBLANK ( [Datediff] ),
        0,
        IF ( _count = 1, _sum, ROUND ( DIVIDE ( _sum, _count - 1 ), 0 ) )
    )

2. Create a table visual 

yingyinr_1-1667812425964.png

 

If the above one can't help you get the desired result, please provide more sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Thanks a lot!

Anonymous
Not applicable

Hi @Milan_TBC ,

Could you please provide some sample data in your order table (exclude sensitive data) with Text format and your expected result with backend logic and special examples. For example: the data in the below table, which value you want to get? And How do you calculate it?  It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

yingyinr_0-1667540364945.png

Best Regards

amitchandak
Super User
Super User

@Milan_TBC,  A new column

 

Diff =

var _max  = maxx(filter(Table, [Customer] = earlier([Customer]) && [Order date] < earlier({order date]) ) , [Order Date])

return

datediff(_max, [Order date], day)

 

Then you can take AVg of this column

 

 

Or move this in a Meausure

 

AverageX(Table,

var _max  = maxx(filter(Table, [Customer] = earlier([Customer]) && [Order date] < earlier({order date]) ) , [Order Date])

return

datediff(_max, [Order date], day) )

 

Earlier, I should have known Earlier: https://youtu.be/CVW6YwvHHi8

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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