Forum Discussion

Davidolis's avatar
Davidolis
Regular Visitor
6 years ago
Solved

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?

 

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

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

     

    which will also work as a measure.

     


    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

8 Replies

  • Nathaniel_C's avatar
    Nathaniel_C
    Community Champion

    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

      • Nathaniel_C's avatar
        Nathaniel_C
        Community Champion

        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.

         


        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

    • Davidolis's avatar
      Davidolis
      Regular Visitor

      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.

      • Nathaniel_C's avatar
        Nathaniel_C
        Community Champion

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

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

         

        which will also work as a measure.

         


        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