Convert excel formula into SQL Access or SQL Server

sellal

New Member
Joined
Aug 24, 2015
Messages
15
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

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
 
Which is exactly what the code I've given you does.

What is not at all clear is how you want to break this down into months - as I mentioned, you need to upload it to a file sharing site and post a link or do as you did before and just put the results directly into your post :)
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Without you posting your desired output, I cannot help you.

I wish you the best of luck and hope someone else can :)
 
Upvote 0
I could, but the logic isn't clear - the formulas aren't consistent.

I'll have a look when I can set some time aside
 
Upvote 0

Forum statistics

Threads
1,221,844
Messages
6,162,346
Members
451,760
Latest member
samue Thon Ajaladin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top