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

[TABLE="width: 539"]
<tbody>[TR]
[TD]Num_
customer

[/TD]
[TD]Purchase_
day

[/TD]
[TD] Name_
Product

[/TD]
[TD]Duration
[/TD]
[TD]31/05/2014
[/TD]
[/TR]
[TR]
[TD]957071417
[/TD]
[TD]22/04/2014
[/TD]
[TD]Product1
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]957074848
[/TD]
[TD]15/04/2014
[/TD]
[TD]Product1
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]958020505
[/TD]
[TD]21/04/2014
[/TD]
[TD]Product1
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]958022300
[/TD]
[TD]25/04/2014
[/TD]
[TD]Product1
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]958023030
[/TD]
[TD]30/04/2014
[/TD]
[TD]Product1
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]958630888
[/TD]
[TD]02/05/2014
[/TD]
[TD]Product2
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]958630888
[/TD]
[TD]03/05/2014
[/TD]
[TD]Product2
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]958630888
[/TD]
[TD]03/05/2014
[/TD]
[TD]Product2
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]958640915
[/TD]
[TD]01/05/2014
[/TD]
[TD]Product2
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]958640915
[/TD]
[TD]02/05/2014
[/TD]
[TD]Product2
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]958640915
[/TD]
[TD]03/05/2014
[/TD]
[TD]Product2
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]958644254
[/TD]
[TD]30/04/2014
[/TD]
[TD]Product2
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]958644440
[/TD]
[TD]03/05/2014
[/TD]
[TD]Product2
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]958646919
[/TD]
[TD]01/05/2014
[/TD]
[TD]Product2
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]958646919
[/TD]
[TD]02/05/2014
[/TD]
[TD]Product2
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]958678805
[/TD]
[TD]03/05/2014
[/TD]
[TD]Product2
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]958704045
[/TD]
[TD]07/04/2014
[/TD]
[TD]Product3
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]958704061
[/TD]
[TD]05/04/2014
[/TD]
[TD]Product3
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]958704061
[/TD]
[TD]25/04/2014
[/TD]
[TD]Product3
[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


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)[TABLE="width: 532"]
<tbody>[TR]
[TD][/TD]
[TD="colspan: 5"]Average Duration (days)
[/TD]
[/TR]
[TR]
[TD]Product
[/TD]
[TD]To
[/TD]
[TD]To
[/TD]
[TD]To
[/TD]
[TD]To
[/TD]
[TD]To
[/TD]
[/TR]
[TR]
[TD]31/05/2014
[/TD]
[TD]30/06/2014
[/TD]
[TD]31/07/2014
[/TD]
[TD]31/08/2014
[/TD]
[TD]06/09/2014
[/TD]
[/TR]
[TR]
[TD]Product1
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]Product2
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]Product3
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
</tbody>[/TABLE]


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

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
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,226,148
Messages
6,189,254
Members
453,534
Latest member
OpsDirJD

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