Crosstab Query Date Range (1 Viewer)

falcondeer

Registered User.
Local time
Yesterday, 17:21
Joined
May 12, 2013
Messages
101
Hi

Could anybody help me figure out why my attached crosstab query asks for date range twice.

Thanks
 

Attachments

  • Crosstab 1.png
    Crosstab 1.png
    67.6 KB · Views: 151
  • Crosstab 2.png
    Crosstab 2.png
    71.5 KB · Views: 137

Minty

AWF VIP
Local time
Today, 01:21
Joined
Jul 26, 2013
Messages
10,366
I think it's possibly because the underlying query is asking for the same parameters?

But I can't see enough of that to tell.
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:21
Joined
Sep 21, 2011
Messages
14,231
You can make the criteria tempvars and set those?
 

falcondeer

Registered User.
Local time
Yesterday, 17:21
Joined
May 12, 2013
Messages
101
You can make the criteria tempvars and set those?
Thanks Gasman

Would you please tell me how to do that, I am done with my project and this is the only thing that I need to make the user able to specify a time period instead of pulling all data since DB created.

I tried this but not working:

PARAMETERS [Start Date] DateTime, [End Date] DateTime;
TRANSFORM Count(qryPrescribedWA.P_MRN) AS CountOfP_MRN
SELECT qryPrescribedWA.PR_Items, Count(qryPrescribedWA.P_MRN) AS [Total Of P_MRN]
FROM qryPrescribedWA
WHERE (((qryPrescribedWA.PR_Date) Between [TempVars]![Start Date] And [TempVars]![End Date]))
GROUP BY qryPrescribedWA.PR_Items
PIVOT qryPrescribedWA.PR_Division;
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:21
Joined
Sep 21, 2011
Messages
14,231
Well you need to define the parameters as the same?

You can use the query without the parameters statement? If you delete that statement in the SQL window and have set the tempvars, it should work.
 

Minty

AWF VIP
Local time
Today, 01:21
Joined
Jul 26, 2013
Messages
10,366
@Gasman - you have to declare the parameters in a cross tab query, it won't work otherwise.
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:21
Joined
Sep 21, 2011
Messages
14,231
@Gasman - you have to declare the parameters in a cross tab query, it won't work otherwise.
Oh really?, sorry, obviously did not know that, but they can be TempVars surely?
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:21
Joined
Sep 21, 2011
Messages
14,231
I was thinking along these lines?
Code:
PARAMETERS [TempVars]![Start] DateTime, [TempVars]![End] DateTime;
TRANSFORM Sum(TestTransactions.ID) AS SumOfID
SELECT TestTransactions.Description, TestTransactions.Category, TestTransactions.TransactionDate, Sum(TestTransactions.ID) AS [Total Of ID]
FROM TestTransactions
WHERE (((TestTransactions.TransactionDate) Between [tempvars]![start] And [tempvars]![end]))
GROUP BY TestTransactions.Description, TestTransactions.Category, TestTransactions.TransactionDate
PIVOT Format([TransactionDate],"mmm") In ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
 

falcondeer

Registered User.
Local time
Yesterday, 17:21
Joined
May 12, 2013
Messages
101
Yes, I don't see why not.
Thanks for the response but still don't know how ! I am not that expert
is it like in the attachment
 

Attachments

  • Crosstab 3.png
    Crosstab 3.png
    84.9 KB · Views: 134

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:21
Joined
May 7, 2009
Messages
19,231
Could anybody help me figure out why my attached crosstab query asks for date range twice
It is Normal to ask Twice because you have 2 criteria, the Start Date and the End Date.
 

Mike Krailo

Well-known member
Local time
Yesterday, 20:21
Joined
Mar 28, 2020
Messages
1,042
Entering a date RANGE twice is not normal.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:21
Joined
May 7, 2009
Messages
19,231
unless this query has same criteria also:

qryPrescribedWA.P_MRN
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:21
Joined
Sep 21, 2011
Messages
14,231
@Gasman - you have to declare the parameters in a cross tab query, it won't work otherwise.
@Minty
I do not want to appear contrary here, but I had to check for myself, as though my memory was bad, I *thought* I had done it before, only because I rarely used the Parameters option? Then again I had not created that many crosstab queries.

I just removed the Parameters line form that crosstab query I posted and it still worked? So what have I missed?

Code:
TRANSFORM Sum(TestTransactions.Amount) AS SumOfAmount
SELECT TestTransactions.Category, Sum(TestTransactions.Amount) AS [Total Of Amount]
FROM TestTransactions
WHERE (((TestTransactions.TransactionDate) Between [tempvars]![start] And [tempvars]![end]))
GROUP BY TestTransactions.Category
PIVOT Format([TransactionDate],"mmm") In ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
 

Minty

AWF VIP
Local time
Today, 01:21
Joined
Jul 26, 2013
Messages
10,366
There is definitely a case when a crosstab won't work without parameters being declared.

After some research - You have got around the requirement by specifying the Column headings.
If you remove those you will get the problem.

See that Allen Browne bloke again for the low-down http://allenbrowne.com/ser-67.html
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:21
Joined
Sep 21, 2011
Messages
14,231
Ahh, OK, I generally would use the wizard at least to create the initial query, and I saw both parameters and column headings mentioned in that link, so would likely always have column headings.
Thank you.
 

Users who are viewing this thread

Top Bottom