A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Calcuate date difference when two dates are same



 
 
Thread Tools Display Modes
  #1  
Old November 28th, 2006, 08:06 PM posted to microsoft.public.access.queries
Satyam
external usenet poster
 
Posts: 4
Default Calcuate date difference when two dates are same

Hi,
I want to calculate (date) difference of column B based on grouping in
column A. Problem is similar to one of the threads on the discussion board
except the fact that for a value in colum A there can be same value in
column B. That is, the desired output should be as shown in column C.

Col-A Col-B Col-C
Xpto 15-Mar 1
Xpto 18-Mar 3
Xpto 18-Mar 0
Xpto 14-Mar
Abc 19-Mar
Abc 21-Mar 2
Abc 23- Mar 2
Dfd 23-Mar
Ttr 24-Abr
Ttr 27-Abr 3

I tried using

SELECT ColA, ColB, ColC
, DMAX("ColB","YourTableOrQuery","ColB#" & ColB & "# AND ColA = """ & ColA
& """") as PriorDate
, DateDiff("d",ColB,DMAX("ColB","YourTableOrQuery"," ColB#" & ColB & "# AND
ColA = """ & ColA & """") )
FROM YourTableOrQuery

but the output I get is as shown in Column D instead of as desired in Col-C

Col-A Col-B Col-C Col-D
Xpto 15-Mar 1 1
Xpto 18-Mar 3 3
Xpto 18-Mar 0 3
Xpto 14-Mar
Abc 19-Mar
Abc 21-Mar 2 2
Abc 23- Mar 2 2
Dfd 23-Mar
Ttr 24-Abr
Ttr 27-Abr 3 2

I would really appreciate any help as I have been stuck this for long.

Thanks,
Satyam


  #2  
Old November 29th, 2006, 05:40 AM posted to microsoft.public.access.queries
Marshall Barton
external usenet poster
 
Posts: 5,361
Default Calcuate date difference when two dates are same

Satyam wrote:
I want to calculate (date) difference of column B based on grouping in
column A. Problem is similar to one of the threads on the discussion board
except the fact that for a value in colum A there can be same value in
column B. That is, the desired output should be as shown in column C.

Col-A Col-B Col-C
Xpto 15-Mar 1
Xpto 18-Mar 3
Xpto 18-Mar 0
Xpto 14-Mar
Abc 19-Mar
Abc 21-Mar 2
Abc 23- Mar 2
Dfd 23-Mar
Ttr 24-Abr
Ttr 27-Abr 3

I tried using

SELECT ColA, ColB, ColC
, DMAX("ColB","YourTableOrQuery","ColB#" & ColB & "# AND ColA = """ & ColA
& """") as PriorDate
, DateDiff("d",ColB,DMAX("ColB","YourTableOrQuery"," ColB#" & ColB & "# AND
ColA = """ & ColA & """") )
FROM YourTableOrQuery

but the output I get is as shown in Column D instead of as desired in Col-C

Col-A Col-B Col-C Col-D
Xpto 15-Mar 1 1
Xpto 18-Mar 3 3
Xpto 18-Mar 0 3
Xpto 14-Mar
Abc 19-Mar
Abc 21-Mar 2 2
Abc 23- Mar 2 2
Dfd 23-Mar
Ttr 24-Abr
Ttr 27-Abr 3 2



Insufficient data!

To do that you **must** have a unique sort order for the
records. Do you have some other field in the table that can
be used to distinguish one Xpto 18-Mar record from another
Xpto 18-Mar record?

--
Marsh
MVP [MS Access]
  #3  
Old November 29th, 2006, 07:44 PM posted to microsoft.public.access.queries
Satyam
external usenet poster
 
Posts: 4
Default Calcuate date difference when two dates are same



"Marshall Barton" wrote:

Satyam wrote:
I want to calculate (date) difference of column B based on grouping in
column A. Problem is similar to one of the threads on the discussion board
except the fact that for a value in colum A there can be same value in
column B. That is, the desired output should be as shown in column C.

Col-A Col-B Col-C
Xpto 15-Mar 1
Xpto 18-Mar 3
Xpto 18-Mar 0
Xpto 14-Mar
Abc 19-Mar
Abc 21-Mar 2
Abc 23- Mar 2
Dfd 23-Mar
Ttr 24-Abr
Ttr 27-Abr 3

I tried using

SELECT ColA, ColB, ColC
, DMAX("ColB","YourTableOrQuery","ColB#" & ColB & "# AND ColA = """ & ColA
& """") as PriorDate
, DateDiff("d",ColB,DMAX("ColB","YourTableOrQuery"," ColB#" & ColB & "# AND
ColA = """ & ColA & """") )
FROM YourTableOrQuery

but the output I get is as shown in Column D instead of as desired in Col-C

Col-A Col-B Col-C Col-D
Xpto 15-Mar 1 1
Xpto 18-Mar 3 3
Xpto 18-Mar 0 3
Xpto 14-Mar
Abc 19-Mar
Abc 21-Mar 2 2
Abc 23- Mar 2 2
Dfd 23-Mar
Ttr 24-Abr
Ttr 27-Abr 3 2



Insufficient data!

To do that you **must** have a unique sort order for the
records. Do you have some other field in the table that can
be used to distinguish one Xpto 18-Mar record from another
Xpto 18-Mar record?

--
Marsh
MVP [MS Access]

Marsh,
I do have a field (Column AA) that distinguishes one Xpto 18-Mar from
another Xpto 18 March.
I am putting up the modified table below.

Col- AA Col-A Col-B Col-C
X1 Xpto 15-Mar 1
X2 Xpto 18-Mar 3
X3 Xpto 18-Mar 0
X4 Xpto 14-Mar
A1 Abc 19-Mar
A2 Abc 21-Mar 2
A3 Abc 23- Mar 2
D1 Dfd 23-Mar
T1 Ttr 24-Abr
T2 Ttr 27-Abr 3

I hope this helps you in suggesting a solution to my problem

Thanks
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:18 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.