Forum Discussion
Average Customer Return Time
- Anonymous3 years ago
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
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
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
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!