I need to convert the Excel formula into SQL Access or SQL server formula
First : The formula in column Duration is :
IF(AND(A2=A3;$E$1>=B3);B3-B2;SI(AND(A2=A3;$E$1<B3);"";IF(AND(A2<>A3;$E$1<=B2);"";$E$1-B2)))
E1 is : 31/05/2014
<tbody>
</tbody>
Second : The formula to calculate Average duration in the cell F4 is :
D is the column of Duration
AVERAGEIFS($D:$D;$D:$D;"<>""";$C:$C;$F4)
<tbody>
</tbody>
Thanks in advance
First : The formula in column Duration is :
IF(AND(A2=A3;$E$1>=B3);B3-B2;SI(AND(A2=A3;$E$1<B3);"";IF(AND(A2<>A3;$E$1<=B2);"";$E$1-B2)))
E1 is : 31/05/2014
Num_ customer | Purchase_ day | Name_ Product | Duration | 31/05/2014 |
957071417 | 22/04/2014 | Product1 | ||
957074848 | 15/04/2014 | Product1 | ||
958020505 | 21/04/2014 | Product1 | ||
958022300 | 25/04/2014 | Product1 | ||
958023030 | 30/04/2014 | Product1 | ||
958630888 | 02/05/2014 | Product2 | ||
958630888 | 03/05/2014 | Product2 | ||
958630888 | 03/05/2014 | Product2 | ||
958640915 | 01/05/2014 | Product2 | ||
958640915 | 02/05/2014 | Product2 | ||
958640915 | 03/05/2014 | Product2 | ||
958644254 | 30/04/2014 | Product2 | ||
958644440 | 03/05/2014 | Product2 | ||
958646919 | 01/05/2014 | Product2 | ||
958646919 | 02/05/2014 | Product2 | ||
958678805 | 03/05/2014 | Product2 | ||
958704045 | 07/04/2014 | Product3 | ||
958704061 | 05/04/2014 | Product3 | ||
958704061 | 25/04/2014 | Product3 |
<tbody>
</tbody>
Second : The formula to calculate Average duration in the cell F4 is :
D is the column of Duration
AVERAGEIFS($D:$D;$D:$D;"<>""";$C:$C;$F4)
Average Duration (days) | |||||
Product | To | To | To | To | To |
31/05/2014 | 30/06/2014 | 31/07/2014 | 31/08/2014 | 06/09/2014 | |
Product1 | | | | | |
Product2 | | | | | |
Product3 | | | | | |
<tbody>
</tbody>
Thanks in advance