Forum Discussion

gustavo_acqio's avatar
gustavo_acqio
Frequent Visitor
7 years ago
Solved

Calculating min, max and average time between two occurances

Hello,   I have a table with date and store, and i want to calculate the time between those two dates in a way that i can get min, max and average days between the two registers.   For instance, ...
  • v-xicai's avatar
    7 years ago

    Hi gustavo_acqio ,

     

    Firstly, create columns Group rank, DateDiff to get days between two accident date for each store.

     

    Group rank = RANKX(FILTER(Table1,Table1[Store]=EARLIER(Table1[Store])),Table1[Date],,ASC,Dense)

     

    DateDiff =

    var pdate= CALCULATE(MAX(Table1[Date]),FILTER(Table1,Table1[Store]=EARLIER(Table1[Store])&&Table1[Group rank]=EARLIER(Table1[Group rank])-1))

    return

    DATEDIFF(pdate,Table1[Date],DAY)

     

    Then, create columns to get min, max and average time between two occurances for each store.

     

    Min_days = CALCULATE(MIN(Table1[DateDiff]),FILTER(ALLSELECTED(Table1),Table1[Store]=EARLIER(Table1[Store])))

     

    Max_days = CALCULATE( MAX(Table1[DateDiff]),FILTER(ALLSELECTED(Table1),Table1[Store]=EARLIER(Table1[Store])))

     

    Avg_days = CALCULATE( AVERAGE(Table1[DateDiff]),FILTER(ALLSELECTED(Table1),Table1[Store]=EARLIER(Table1[Store])))

     

    When make some selections in slicer, return result showing picture below.

     

     

     

     

     

     

     

     

     

     

     

     

    Here is my test pbix: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EaABQf0lJCZKssZatFErw_gBo6wAFMnFtIfPUp-EYeU-ww?e=M6JkPk

     

    Best Regards,

    Amy

     

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