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
Davidolis
Regular Visitor

Find time between entries in same column

Hi,

 

I have a table which has 2 columns. One column (number) represents units with serial numbers that are unique. The other column (date - day) is which date the serial numbers are entered.

 

Each entry has one row. So a serial number will show up in multiple rows, depending on how often it is entered.

 

I want to find out how many days between each time a serial number is entered, in days. Then find the average for how often they are entered again. There is no limit for how many times a serial number can show up in the list.

 

I have tried grouping and other weird stuff, but my understanding of DAX is pretty weak. Could someone please help me out here?

 

1 ACCEPTED SOLUTION

Hi @Davidolis , @amitchandak ,
The last column is the average overall.

AverageX = AVERAGEX(serialN,IF(serialN[Datediff]=BLANK() && serialN[Average time]>0,serialN[Average time]))

aver1.PNG

 

which will also work as a measure.

aver12.PNG

 


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

8 REPLIES 8
Nathaniel_C
Super User
Super User

Hi @Davidolis , @amitchandak ,
This will get you part way.

Datediff =
VAR _curdate = 'serialN'[Column2]
VAR _prevDate =
    CALCULATE (
        MAX ( serialN[Column2] ),
        ALLEXCEPT ( serialN, serialN[Column1] ),
        ( serialN[Column2] ) < _curdate
    )
VAR _calc =
    CALCULATE (
        DATEDIFF ( _prevDate, _curdate, DAY ),
        ALLEXCEPT ( 'serialN', 'serialN'[Column1] )
    )
RETURN
    _calc

Get the current date, get the previous date, use DateDiff to calculate the time between.
Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




serial.PNG

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @Davidolis , @amitchandak ,
And the second column

Average time =
VAR _sum =
    CALCULATE ( SUM ( serialN[Datediff] ), ALLEXCEPT ( serialN, serialN[Column1] ) )
VAR _count =
    CALCULATE (
        COUNT ( serialN[Column1] ),
        ALLEXCEPT ( serialN, serialN[Column1] )
    ) - 1
RETURN
    DIVIDE ( _sum, _count )

Get the sum, get the count - 1, Divide for average.
aver.PNG

 


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




amitchandak
Super User
Super User

Try EARLIER

https://community.powerbi.com/t5/Desktop/Explanation-of-the-EARLIER-formula/td-p/529469

https://docs.microsoft.com/en-us/dax/earlier-function-dax

 

The information you have provided is not making the problem clear to me. Can you please explain with an example. If possible please share a sample pbix file after removing sensitive information.
Thanks

Hi, sorry if it wasn't clear i will make an example

 

1234567891.1.2018
9876543212.5.2019
1245789455.5.2018
1234567894.5.2019
5541234796.6.2019
98765432110.11.2019
1234567899.11.2019

 

An entry can show up multiple times and I need to know how long on average between each entry and then average for all. Is this helpful? I haven't attempted the proposed solutions yet, just thought i would do my part first.

Hi @Davidolis , @amitchandak ,
The last column is the average overall.

AverageX = AVERAGEX(serialN,IF(serialN[Datediff]=BLANK() && serialN[Average time]>0,serialN[Average time]))

aver1.PNG

 

which will also work as a measure.

aver12.PNG

 


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




@Nathaniel_C This is great, Thank you so much! 

 

I had some problems getting the last one to work, but it needed a ; instead of a, in the last parameter for the IF. 

 

Thank you so much for helping me out! The examples really let me walk through it and understand how to do it. Without that table i would not have been able to recreate it...😕 Thanks again Nathan!

 

 

 

Hi @Davidolis ,
You are very welcome! Thank you for your kind words. DAX is pretty amazing stuff.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.