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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
pbi_baller
Frequent Visitor

Length Between Purchases

Hi Experts,

 

I am trying to calculate the length between all customers first and second purchase. Here is a measure I have:

 

VAR temptable =
ADDCOLUMNS (
VALUES ( 'Table'[date] ),
"RANK", RANKX (
VALUES ( 'Table'[date] ),
'Table'[date],
,
DESC,
DENSE
)
)
RETURN 
DATEDIFF (
MINX ( FILTER ( temptable, [RANK] = 2 ), 'Table'[date] ),
MINX ( FILTER ( temptable, [RANK] = 1 ),'Table'[date]),
DAY
) )
 
This works when put in a table with all customer id's and evaluates each customer indivdually.
 
Does anyone know how I can write a measure that will calculate a single figure which sums the length for all customers.
 
I.e. customer 1 has a length of 14 days and customer 2 has a length of 1 day. The measure will then display a figure of 15. 
 
Thanks in advance!
1 ACCEPTED SOLUTION

Hi @pbi_baller ,

 

I suggest you to create a new measure based on the original measure you created before.

 

Diff with correct total = SUMX(VALUES('Table'[Customer ID]),[Basic])

 

Result is as below.

RicoZhou_0-1656487266195.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
rajulshah
Super User
Super User

Hello @pbi_baller ,

 

Can you please share your sample data structure?

Fact table looks like this:

 

pbi_baller_0-1655976761561.png

Date is measure above refers to purchase date.

 

I hope that helps, cannot share the file for confidential reasons

Hi @pbi_baller ,

 

I suggest you to create a new measure based on the original measure you created before.

 

Diff with correct total = SUMX(VALUES('Table'[Customer ID]),[Basic])

 

Result is as below.

RicoZhou_0-1656487266195.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.