We help IT Professionals succeed at work.

Dynamic labels in a crosstab query used in calculation

avoorheis asked
Last Modified: 2010-05-18
I need to do some calculations on some monthly totals which are labeled with the month and year. I'll be doing this monthly, so, the labels will change (like 8/07, 9/07, 10/07 then 9/07, 10/07, 11/07).
Currently, I'm using a crosstab query to populate a spreadsheet with this data, I need to the data corresponding to the months in a single row for each record.

I'm trying to figure out a way to compare the last 2 months of data, but, since the labels change each month, I'm not sure how to accomplish this.

Using the crosstab as a subquery, the query where I want to do the calculations looks something like:
SELECT DISTINCT tblSEODashBoardData.WEB_ID, tblSEODashBoardData.ActDt, qrySEODashBoardDataChart.[05/07], qrySEODashBoardDataChart.[06/07], qrySEODashBoardDataChart.[07/07], qrySEODashBoardDataChart.[08/07], qrySEODashBoardDataChart.[09/07], qrySEODashBoardDataChart.[10/07], ([10/07]/[09/07])-1 AS ChangeFromLast
FROM tblSEODashBoardData LEFT JOIN qrySEODashBoardDataChart ON tblSEODashBoardData.WEB_ID = qrySEODashBoardDataChart.WEB_ID
WHERE (((tblSEODashBoardData.WEB_ID) Is Not Null))
ORDER BY tblSEODashBoardData.WEB_ID;

So, in this case I need to figure out what to use for labels instead of the mm/yy, or maybe there a better way to handle this.

Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)


thanks David, very helpful, and I'll probably end up going that way.

Although, I'm now very curious if there actually is a way to relabel or rename the those column headings. Seems like this sort of thing would come up often.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.