Link to home
Start Free TrialLog in
Avatar of NiceMan331
NiceMan331

asked on

adding another column head to cross tab query

i have sales transactions by store / date
i already did cross tab query like this :
TRANSFORM Sum(WeekAvg.DayAvg) AS SumOfDayAvg
SELECT WeekAvg.Store, Sum(WeekAvg.DayAvg) AS [Total Of DayAvg]
FROM WeekAvg
GROUP BY WeekAvg.Store
PIVOT WeekAvg.WekNo;

Open in new window

this will show store as row heading , WeekNumberOf The Year
and sales amount as row values
i woulk like to add also 2 cloumns under the week values to display the firstdayof week and last day of the week
i have the function already , but i want help in adding it to the cross tab query
Avatar of Phillip Burton
Phillip Burton

I don't know exactly what you mean, but suspect it cannot be done easily.

In Microsoft Access' crosstab queries, you can only have one Column Heading and one Value option.
Avatar of NiceMan331

ASKER

ok , in conclusion , my cross tab gives week numbers at comun heading
any other way to select or to display the starting data and ending date of the week number ?
Avatar of Dale Fye
can you provide an example, perhaps an screenshot of what you would like it to look like in Excel?  and maybe some sample data as it is configured in your table.
I would suggest using some functions in a form, i.e. not part of the query itself, but as Text Boxes.

It would help if you could provide what Dale has asked for, and also what is the start of Week 1 of this year is for your calculations.
here are the data as now  ,
before.png
and here as what i wish to add
After.png
You can't do that in a query.

But you can create a report or form. Insert the week data in the header and the query data in the details section.
Or you can create an empty form and just drag-and-drop the query to create a subform with datasheetview of your data. Then insert the week data in the header.

/gustav
The above would make your Week 1 start on Sunday 29 December 2013 - is this correct?
this is doable, if you will export the crosstab query to excel and manipulate the Excel file using VBA codes.
gustav
But you can create a report or form
may be this is the best solution , but the problem is if i have 52 weeks , i can't image that access report may be fit in one page

philip
The above would make your Week 1 start on Sunday 29 December 2013 - is this correct?
i have no problem about the value of the starting date , the function i use return correct value for me

rey
this is doable, if you will export the crosstab query to excel and manipulate the Excel file using VBA codes.
good suggestion , because i have to do chart in excell based on that query , but i have no experiance in how to make the manipulation in excell
>  the problem is if i have 52 weeks , i can't image that access report may be fit in one page ...

No, it won't. In fact, nothing will. But with a form having the crosstab as a subform, you can scroll horisontally and/or hide columns of little or no interest.

/gustav
but any how i have to export it to excell to do chart analyse
Then you would export the crosstab to Excel, either a worksheet or a Named Range.

Look up the on-line help for:

    DoCmd.OutputTo
    DoCmd.TransferSpreadsheet

/gustav
<good suggestion , because i have to do chart in excell based on that query , but i have no experiance in how to make the manipulation in excell >

how much do you know about VBA codes ?
how much do you know about VBA codes ?
i have a lot in VBA for access
but for excell and itc cells , i didn't do it before
rey
i tried to upload the file here but it not accepted
here is sql for query weeklyavg
SELECT Accepted_Trans.Store, Accepted_Trans.WekNo, Sum(Accepted_Trans.Sales_Amt) AS SumOfSales_Amt, Count(Accepted_Trans.Trans_Date) AS CountOfTrans_Date, Sum(Accepted_Trans.Sales_Amt)/Count(Accepted_Trans.Trans_Date) AS DayAvg, First(Accepted_Trans.FrstDayWeek) AS FirstOfFrstDayWeek, Last(Accepted_Trans.LstDayWeek) AS LastOfLstDayWeek
FROM Accepted_Trans
GROUP BY Accepted_Trans.Store, Accepted_Trans.WekNo;

Open in new window

@NiceMan

zip the db and upload.
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent
Thanx
by the way , i just have small question in exporting to Excell
what is the code if i want to open a query , select specific data , and copy it to a specific cell in excell
for example if i want in same our example to only copy value of store number 135 where weeks in (5 to 10)
just create another query with this statement and save as "myQuery"

TRANSFORM Sum(WeekAvg.DayAvg) AS SumOfDayAvg
SELECT WeekAvg.Store
FROM WeekAvg
WHERE (((WeekAvg.Store)=135))
GROUP BY WeekAvg.Store
PIVOT WeekAvg.WekNo In(5,6,7,8,9,10)

then in the code to export to excel, change

Set rs = CurrentDb.OpenRecordset("WeekAvgByStore")

with

Set rs = CurrentDb.OpenRecordset("myQuery")
ok , thanx rey