Forum Discussion

TheGreatestGoat's avatar
TheGreatestGoat
Frequent Visitor
8 years ago
Solved

Calculate A Customer's Second Order

Hi There,   I am trying to calculate the time between a customer's first order and second order. I have been able to calculate the difference between first and last date as follows using measures: ...
  • Zubair_Muhammad's avatar
    8 years ago

    HI TheGreatestGoat

     

    You can try this MEASURE pattern

     

    Days between second order and third order =
    VAR temp =
        ADDCOLUMNS (
            VALUES ( 'Sales Fact Table'[purchase_Date] ),
            "RANK", RANKX (
                VALUES ( 'Sales Fact Table'[purchase_Date] ),
                [purchase_Date],
                ,
                DESC,
                DENSE
            )
        )
    RETURN
        DATEDIFF (
            MINX ( FILTER ( temp, [RANK] = 3 ), [purchase_Date] ),
            MINX ( FILTER ( temp, [RANK] = 2 ), [purchase_Date] ),
            DAY
        )
  • Zubair_Muhammad's avatar
    Zubair_Muhammad
    8 years ago

    TheGreatestGoat

     

    Try this MEASURE to do the average

     

    Measure =
    AVERAGEX (
        ALLSELECTED ( 'Sales Fact Table'[Customer] ),
        [Days between second order and third order]
    )