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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
filarap
Helper III
Helper III

Creating table with unique values and min/max timestamps

Hi all,

 

I am strugling to create calculation based on unique values from a table.

I need to calculate average duration using only unique ID taking earliest and oldest timestamps. 

One ID should only have one create and close in table to have correct calculation. Please see table 3 for what i need:

 

WHat i started with:

table 1

IDClosedCreatedDuration
105/09/201914/09/20199
207/09/201915/09/20198
310/09/201913/09/20193
108/09/201915/09/20197
208/09/201914/09/20196
105/09/201913/09/20198
402/09/201914/09/201912

 

Then i managed to create:

table 3

IDClosedCreatedDurationEarliestOldestDuration per case
105/09/201914/09/2019905/09/201915/09/201910
207/09/201915/09/2019807/09/201915/09/20198
310/09/201913/09/2019310/09/201913/09/20193
108/09/201915/09/2019705/09/201915/09/201910
208/09/201914/09/2019607/09/201915/09/20198
105/09/201913/09/2019805/09/201915/09/201910
402/09/201914/09/20191202/09/201913/09/201911

 

And then i already cteated new table with unique values (using VALUES()). Not sure if this is the best way, but the one i have so far. What i need in the end is:

table 3

 

IDEarliestOldestDuration per case
105/09/201915/09/201910
207/09/201915/09/20198
310/09/201913/09/20193
402/09/201913/09/201911

 

So my Average is 8 insteaed 8.7

 

Please help with methodology

Regards

Filarap

1 ACCEPTED SOLUTION
v-xuding-msft
Community Support
Community Support

Hi @filarap ,

By my test, the oldest date of ID 4 should be 14/09/2019. Are you sure that the output is right (13/09/2019 )? If the date is 14/09/2019, the average value is 8.7. The following is my formulas. And I attached my sample that you can reference.

 

Calculated column:
Earliest = CALCULATE(MIN('Table'[Closed]),ALLEXCEPT('Table','Table'[ID])) Oldest = CALCULATE(MAX('Table'[Created]),ALLEXCEPT('Table','Table'[ID])) Duration per case = DATEDIFF('Table'[Earliest],'Table'[Oldest],DAY)
AVG = AVERAGE('Table'[Duration per case])
Measure:
Average = AVERAGE('Table'[Duration per case])

4.PNG

Best Regards,

Xue Ding

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

 

 

Best Regards,
Xue Ding
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

2 REPLIES 2
v-xuding-msft
Community Support
Community Support

Hi @filarap ,

By my test, the oldest date of ID 4 should be 14/09/2019. Are you sure that the output is right (13/09/2019 )? If the date is 14/09/2019, the average value is 8.7. The following is my formulas. And I attached my sample that you can reference.

 

Calculated column:
Earliest = CALCULATE(MIN('Table'[Closed]),ALLEXCEPT('Table','Table'[ID])) Oldest = CALCULATE(MAX('Table'[Created]),ALLEXCEPT('Table','Table'[ID])) Duration per case = DATEDIFF('Table'[Earliest],'Table'[Oldest],DAY)
AVG = AVERAGE('Table'[Duration per case])
Measure:
Average = AVERAGE('Table'[Duration per case])

4.PNG

Best Regards,

Xue Ding

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

 

 

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

Hi Xue Ding,

 

You are correct, my error here.

 

Thank you for help, i managed to do it with your solution.

 

Regards

Filarap

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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