cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Matt_Alexander
Advocate III
Advocate III

DATEDIFF between duplicate IDs

Hi all,

 

Wondering if anyone could help me work out how to approach the following challenge:

 

I have a table with millions of IDs in one columns, and dates of when they were sold in another.

 

In the event that an ID is repeated, it means the product has been resold and I need to calculate the average datediff between those two dates for the repeated IDs.

 

Would the best approach be to create another table by performing a Group By on the IDs? If so how would I then use the datediff to only calculate between the two dates relating to the repeated IDs?

 

Many thanks for any direction on this one!

 

Matt

 

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

So... we take the max(date sold) minus min(date sold) giving us the total # of days between sales, then divide by the number of sales (minus 1)... and that gives the average number of days between sales?   I think?

 

Jan 1, 2017

Jan 9, 2017

  ... 8 days between sales  -- Jan 9 - Jan 8 / (2 sales - 1) = 8

 

Jan 1, 2017

 Jan 2, 2017

Jan 9, 2017

  ... still 8 days, but now with another sale, we get average of 4 days.  The exact date off the "middle" sale doesn't matter, at least in my head!?    Currently Jan2-Jan1=1, Jan9-Jan2=7,  (7+1)/2=4 ?

Avg Days Between Sale := DIVIDE(MAX(MyTable[SaleDate]) - MIN(MyTable[SaleDate]), COUNTROWS(MyTable) - 1)

 

Maybe?! 🙂

View solution in original post

Hi again,

 

Qucik update, it turns out that my technical indications were incorrect and the sales are not going to coming through this way.

 

However, intrigued by the suggestion I've had a quick look through but can't seem to get it to work:

 

IDDate SoldTime taken to sell   
101/01/20170   
103/01/20172   
305/01/20170 Average Days to Sell
310/01/20175 3,5 
      
 Jan10-Jan1 / 2 sales = 5?   
 Jan10-Jan1 / (2-1) sales = 10?   

 

Many thanks for your help anyway.

 

Matt

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

What if the same ID comes up ... 3 times?  47 times?

Hi @Anonymous

 

Good question! The time taken between each date (sale) should be included in the average calculation.

 

A product (the same ID) can be sold numerous times.

 

Let me know if you need any further information!

 

Thanks,

 

Matt

Anonymous
Not applicable

So... we take the max(date sold) minus min(date sold) giving us the total # of days between sales, then divide by the number of sales (minus 1)... and that gives the average number of days between sales?   I think?

 

Jan 1, 2017

Jan 9, 2017

  ... 8 days between sales  -- Jan 9 - Jan 8 / (2 sales - 1) = 8

 

Jan 1, 2017

 Jan 2, 2017

Jan 9, 2017

  ... still 8 days, but now with another sale, we get average of 4 days.  The exact date off the "middle" sale doesn't matter, at least in my head!?    Currently Jan2-Jan1=1, Jan9-Jan2=7,  (7+1)/2=4 ?

Avg Days Between Sale := DIVIDE(MAX(MyTable[SaleDate]) - MIN(MyTable[SaleDate]), COUNTROWS(MyTable) - 1)

 

Maybe?! 🙂

Hi again,

 

Qucik update, it turns out that my technical indications were incorrect and the sales are not going to coming through this way.

 

However, intrigued by the suggestion I've had a quick look through but can't seem to get it to work:

 

IDDate SoldTime taken to sell   
101/01/20170   
103/01/20172   
305/01/20170 Average Days to Sell
310/01/20175 3,5 
      
 Jan10-Jan1 / 2 sales = 5?   
 Jan10-Jan1 / (2-1) sales = 10?   

 

Many thanks for your help anyway.

 

Matt

Interesting approach, let me have a play around and see what the results are!

 

Thank you for the suggestion @Anonymous

Hi @Matt_Alexander,

If you still do not resolved your problem, you'd better post some sample table for further analysis. And welcome to share your workaround and mark the helpful reply as answer if you have resolved it.

Best Regards,
Angelia

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

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

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors