473,413 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Crosstab Query using date ranges

I am trying to get a crosstab query (in access 2000) to group data by date range.

Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Sum(tblInvoice.InvBalance) AS SumOfInvBalance
  2. SELECT tblInvoice.DealerID, Sum(tblInvoice.InvBalance) AS [Total Of InvBalance]
  3. FROM tblInvoice
  4. GROUP BY tblInvoice.DealerID
  5. PIVOT Format(Now(),"ww");
I know the above code is wrong! My question is how do I get the query to group outstanding Invoice Balances (InvBalance) into the following date ranges (InvDate):
0 - 29 days, 30 - 59 days, 60 - 89 days, 90+ days

I am trying to develop a Debtors List by Dealer (DealerID) eg.

0 - 29 days 30 - 59 days 60 - 89 days 90+ days
Dealer1 £50 £250
Dealer2 £234 £453 £5
Dealer3 £23 £68 £1000


Hope this makes sense
Apr 25 '07 #1
22 4963
NeoPa
32,556 Expert Mod 16PB
I'm no good with CrossTabs at all, but couldn't you make up a field in your source (or underlying) query that uses the Switch() function to return the groupings that you want :
Expand|Select|Wrap|Line Numbers
  1. Switch([InvDate]-Date()<30,"A",[InvDate]-Date()<60,"B",[InvDate]-Date()<90,"C",TRUE,"D")
Grouping by the result of this should do what you want.
Apr 26 '07 #2
I'm no good with CrossTabs at all, but couldn't you make up a field in your source (or underlying) query that uses the Switch() function to return the groupings that you want :
Expand|Select|Wrap|Line Numbers
  1. Switch([InvDate]-Date()<30,"A",[InvDate]-Date()<60,"B",[InvDate]-Date()<90,"C",TRUE,"D")
Grouping by the result of this should do what you want.

Hi
Will this work in MS Access 2000?
Apr 27 '07 #3
NeoPa
32,556 Expert Mod 16PB
You still need to incorporate it into your CrossTab query properly, but the function call itself should work in Access 2K, yes.
Apr 27 '07 #4
You still need to incorporate it into your CrossTab query properly, but the function call itself should work in Access 2K, yes.

BAFFLED!!

Have tried the following, plus variations of, to no avail!

TRANSFORM Sum(tblInvoice.InvBalance) AS SumOfInvBalance
SELECT tblInvoice.DealerID, Count(tblInvoice.DealNo) AS CountOfDealNo, Sum(tblInvoice.InvBalance) AS [Total Of InvBalance]
FROM tblInvoice
GROUP BY tblInvoice.DealerID
PIVOT Switch([InvDate] Between Now() And Now()=30,"0-30 Days",[InvDate] Between Date()+30 And Date()+60,"30 - 60 Days",[InvDate] Between Date()+60 And Date()+90,"60 - 90 Days",[InvDate]-Date()+90,"90+ Days");

Any ideas?

Thanks
Apr 27 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
Try this ...
Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Sum(tblInvoice.InvBalance) AS SumOfInvBalance
  2. SELECT tblInvoice.DealerID, Count(tblInvoice.DealNo) AS CountOfDealNo, Sum(tblInvoice.InvBalance) AS [Total Of InvBalance]
  3. FROM tblInvoice
  4. GROUP BY tblInvoice.DealerID
  5. PIVOT  IIf([InvDate] Between Now() And Now()+30,"0-30 Days",
  6. IIf([InvDate] Between Date()+30 And Date()+60,"30 - 60 Days",IIf([InvDate] Between Date()+60 And Date()+90,"60 - 90 Days","90+ Days")));
  7.  
Mary
Apr 28 '07 #6
Try this ...
Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Sum(tblInvoice.InvBalance) AS SumOfInvBalance
  2. SELECT tblInvoice.DealerID, Count(tblInvoice.DealNo) AS CountOfDealNo, Sum(tblInvoice.InvBalance) AS [Total Of InvBalance]
  3. FROM tblInvoice
  4. GROUP BY tblInvoice.DealerID
  5. PIVOT  IIf([InvDate] Between Now() And Now()+30,"0-30 Days",
  6. IIf([InvDate] Between Date()+30 And Date()+60,"30 - 60 Days",IIf([InvDate] Between Date()+60 And Date()+90,"60 - 90 Days","90+ Days")));
  7.  
Mary
Hi Mary
I think we are somewhere close, but at this moment all records are being placed in 90+ days whereas some records are within 30 - 60 days range etc.

I am trying to create a list of customers outstanding invoices by date range ( a "Debtors List") so that I know which are the oldest ane therefore need 'chasing' for payment. Am I going in the right direction with a Crosstab Query? Or is there a simpler solution?

Thanks.
Apr 29 '07 #7
Hi Mary
I think we are somewhere close, but at this moment all records are being placed in 90+ days whereas some records are within 30 - 60 days range etc.

I am trying to create a list of customers outstanding invoices by date range ( a "Debtors List") so that I know which are the oldest ane therefore need 'chasing' for payment. Am I going in the right direction with a Crosstab Query? Or is there a simpler solution?

Thanks.
Hi Mary

SOLVED IT!!!

Thank you so much for your help (and "NeoPa")

I changed the "+" to a "-" (Iif Now()-30 And Now()-60 ) and HAPPY DAYS! it works.

You guys are Brilliant!

Bruce
Apr 29 '07 #8
Next problem:

I would like to filter the data by "Broker", but get a message:
The Microsoft Jet Database Engine does not recognize "Forms!frmMainForm.Text265" as a valid field name or expression.

The field Text265 is on a form (frmMainForm) and holds the logged on "Brokers" initials. I have entered this as the criteria in the query but it gives the above massage when run.

I have tried : "Like", "=" but still get the message, any ideas as to how I filter the data to a given Brokers Initials?

Thanks
Apr 29 '07 #9
MMcCarthy
14,534 Expert Mod 8TB
Next problem:

I would like to filter the data by "Broker", but get a message:
The Microsoft Jet Database Engine does not recognize "Forms!frmMainForm.Text265" as a valid field name or expression.

The field Text265 is on a form (frmMainForm) and holds the logged on "Brokers" initials. I have entered this as the criteria in the query but it gives the above massage when run.

I have tried : "Like", "=" but still get the message, any ideas as to how I filter the data to a given Brokers Initials?

Thanks
Open the properties for Text265 in form design view. Under the other tab check the Name property. Is it Text265?
Apr 29 '07 #10
NeoPa
32,556 Expert Mod 16PB
Boliches,
Sorry I couldn't get back to you before now, but your version of what I posted was quite different from mine.
Switch is the better function in this case I believe, but using Date() reather than Now() is absolutely imperative here.

It seems you have it working, so good for you (and Mary of course), but I would nevertheless recommend (whether you use Switch(), IIf() etc whatever), that you use Date() but not Now().
Apr 30 '07 #11
Open the properties for Text265 in form design view. Under the other tab check the Name property. Is it Text265?
Hi

Thanks for your interest in my problem. I am using the Text265 text box in various forms to filter data with success, however it only becomes unrecognizable in this crosstab query! I have used the filter in another crosstab, again with success, whilst trying to create the finished query.

It doesnt seem to make much sense.

Any ideas?
Apr 30 '07 #12
Boliches,
Sorry I couldn't get back to you before now, but your version of what I posted was quite different from mine.
Switch is the better function in this case I believe, but using Date() reather than Now() is absolutely imperative here.

It seems you have it working, so good for you (and Mary of course), but I would nevertheless recommend (whether you use Switch(), IIf() etc whatever), that you use Date() but not Now().
Thanks for returning,

I was using both Date() and Now() in the code and have now changed all to Date(). (Still working!)

Regarding "Switch()" I just couldnt get it to work, I bet I was just being thick, or my coding was incorrect or something equally stupid. I would still like to try this function now just for the hell of it, but feel I need to be pointed in the right direction.

But only if you have the time!

Thanks
Apr 30 '07 #13
MMcCarthy
14,534 Expert Mod 8TB
Hi

Thanks for your interest in my problem. I am using the Text265 text box in various forms to filter data with success, however it only becomes unrecognizable in this crosstab query! I have used the filter in another crosstab, again with success, whilst trying to create the finished query.

It doesnt seem to make much sense.

Any ideas?
Are you sure frmMainForm is open when this query is running?
Apr 30 '07 #14
NeoPa
32,556 Expert Mod 16PB
Thanks for returning,

I was using both Date() and Now() in the code and have now changed all to Date(). (Still working!)
Great.
Regarding "Switch()" I just couldnt get it to work, I bet I was just being thick, or my coding was incorrect or something equally stupid. I would still like to try this function now just for the hell of it, but feel I need to be pointed in the right direction.

But only if you have the time!

Thanks
Expand|Select|Wrap|Line Numbers
  1. Switch([InvDate]-Date()<30,"A", _
  2.        [InvDate]-Date()<60,"B", _
  3.        [InvDate]-Date()<90,"C", _
  4.        TRUE,"D")
How you incorporate this function call into your CrossTab I'll leave up to you (and or Mary), but essentially it is a multiple If / ElseIf construct.
I've laid it out in the relevant pairs of parameters to make it more obvious for you (Same code as before).
In each pair, the first is the comparison, and the second is the result to be returned. [InvDate]-Date() is a calculation that returns the number of days until [InvDate]. If the first pair are ignored ([InvDate]-Date()<30 is FALSE) then the second pair cut in, BUT, at this stage you already know that it is >=30. This means the second test is equivalent to 30<[InvDate]-Date()<60. The last pair has a test of TRUE, which means that one result is always returned.
Apr 30 '07 #15
Are you sure frmMainForm is open when this query is running?


Yes definitely open, with the text box correctly filled in!
May 1 '07 #16
MMcCarthy
14,534 Expert Mod 8TB
Yes definitely open, with the text box correctly filled in!
Ok click in the criteria and then click on the build wizard. Choose the correct form and then select Text265 form the list and then click Value. See if that makes any difference.
May 1 '07 #17
Ok click in the criteria and then click on the build wizard. Choose the correct form and then select Text265 form the list and then click Value. See if that makes any difference.
In the crosstab query I have put the following:

TRANSFORM Sum(tblInvoice.InvBalance) AS SumOfInvBalance
SELECT tblInvoice.DealerID, Count(tblInvoice.DealNo) AS CountOfDealNo, Sum(tblInvoice.InvBalance) AS [Total Of InvBalance]
FROM tblInvoice
WHERE (((tblInvoice.Broker)=[Forms]![frmMainForm]![Text265]))
GROUP BY tblInvoice.DealerID
PIVOT IIf([InvDate] Between Date() And Date()-30,"0-30 Days",IIf([InvDate] Between Date()-30 And Date()-60,"30 - 60 Days",IIf([InvDate] Between Date()-60 And Date()-90,"60 - 90 Days",IIf([InvDate]=Date()-90,"90+ Days"))));

Couldnt see where to put "Value" in the Build - hence still not working!

Regards
May 2 '07 #18
MMcCarthy
14,534 Expert Mod 8TB
In the crosstab query I have put the following:

TRANSFORM Sum(tblInvoice.InvBalance) AS SumOfInvBalance
SELECT tblInvoice.DealerID, Count(tblInvoice.DealNo) AS CountOfDealNo, Sum(tblInvoice.InvBalance) AS [Total Of InvBalance]
FROM tblInvoice
WHERE (((tblInvoice.Broker)=[Forms]![frmMainForm]![Text265]))
GROUP BY tblInvoice.DealerID
PIVOT IIf([InvDate] Between Date() And Date()-30,"0-30 Days",IIf([InvDate] Between Date()-30 And Date()-60,"30 - 60 Days",IIf([InvDate] Between Date()-60 And Date()-90,"60 - 90 Days",IIf([InvDate]=Date()-90,"90+ Days"))));

Couldnt see where to put "Value" in the Build - hence still not working!

Regards
It doesn't need Value. When you say it's not working do you mean you are getting an error or just no results?
May 2 '07 #19
It doesn't need Value. When you say it's not working do you mean you are getting an error or just no results?

Sorry for the delay in replying!

I get an error message:

The Microsoft Jet Database Engine does not recognize '[Forms]![frmMainForm]![Text265]' as a valid field name or expression.

Any ideas?
May 4 '07 #20
Great.

Expand|Select|Wrap|Line Numbers
  1. Switch([InvDate]-Date()<30,"A", _
  2.        [InvDate]-Date()<60,"B", _
  3.        [InvDate]-Date()<90,"C", _
  4.        TRUE,"D")
How you incorporate this function call into your CrossTab I'll leave up to you (and or Mary), but essentially it is a multiple If / ElseIf construct.
I've laid it out in the relevant pairs of parameters to make it more obvious for you (Same code as before).
In each pair, the first is the comparison, and the second is the result to be returned. [InvDate]-Date() is a calculation that returns the number of days until [InvDate]. If the first pair are ignored ([InvDate]-Date()<30 is FALSE) then the second pair cut in, BUT, at this stage you already know that it is >=30. This means the second test is equivalent to 30<[InvDate]-Date()<60. The last pair has a test of TRUE, which means that one result is always returned.
For some reason everything (all results) end up in column "A", whereas the results should be in there appropriate section! eg.


Expand|Select|Wrap|Line Numbers
  1. Dealer    Count     Total   30- 60 Days  60 - 90 Days
  2. Adams       1     £74.91                     £74.91
  3. Magnus     18  £1,582.63     £146.88      £1,435.75
  4. Murketts   18    £937.06     £292.28        £644.78
May 4 '07 #21
NeoPa
32,556 Expert Mod 16PB
For some reason everything (all results) end up in column "A", whereas the results should be in there appropriate section! eg.


Expand|Select|Wrap|Line Numbers
  1. Dealer    Count     Total   30- 60 Days  60 - 90 Days
  2. Adams       1     £74.91                     £74.91
  3. Magnus     18  £1,582.63     £146.88      £1,435.75
  4. Murketts   18    £937.06     £292.28        £644.78
You don't say what SQL you used Boliches.
My function (as I thought I'd made very clear) only enables you to determine which group each item is in. It is not a Cross-Tab query.
Or did you even mean to quote my post at all?
May 4 '07 #22
You don't say what SQL you used Boliches.
My function (as I thought I'd made very clear) only enables you to determine which group each item is in. It is not a Cross-Tab query.
Or did you even mean to quote my post at all?
As I stated earlier I was interested in your idea of using the Switch finction, however Yes I am using a crosstab query, I did enquire as to how and where I would use the Swich() - prehaps we have been at crossed purposes!

I have the crosstab working producing the required results, so thanks for your time.

Regards
May 5 '07 #23

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Donna Sabol | last post by:
First, I should start by saying I am creating a database to be used by some very impatient, non-computer literate people. It needs to be seameless in it's operation from their point of view. I...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
2
by: Sherman H. | last post by:
I have a few questions for crosstab and popup form questions: 1. I created a crosstab as follows: IT Financial Operation John 21 22 ...
2
by: carl.barrett | last post by:
Hi, I'm back with the same question as I still can't get it to display my data the way I want it to. The table lists information about a perpetrator involved with an anti social behaviour...
2
by: Claus Haslauer | last post by:
Hi, I want to create a crosstab query that looks like this Date | Elevation 1 | Elevation 2 | ... ______________________________________________________________________ Date 1 | xx.y | xx.y...
2
by: deejayquai | last post by:
Hi I'm trying to produce a report based on a dynamic crosstab. Ultimately i'd like the report to actually become a sub report within a student end of year record of achievement. The dynamic...
14
by: Tina | last post by:
My employer tracks productivity/performance of clinicians (how much they bill) each week, its averages for the month, and the 6 months. These averages are compared to their expected productivity....
4
by: m.wanstall | last post by:
I have a crosstab query that compiles data for Months of the year. I have a stacked select query on top of that crosstab query that uses the latest 2 months data and exports it to a fixed length...
2
by: Jim Devenish | last post by:
I wish to create a crosstab query as the record source for a report. It needs to count data between selected dates which are entered by the user in a popup window. The following Select query...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.