Link to home
Start Free TrialLog in
Avatar of kwarden13
kwarden13

asked on

Access Query - Create Crosstab?

How can I create a query to show spend and revenue by vendor? I have the following in the database attached.

1) tbl_spend - spend by supplier
2) tbl_rev - revenue by supplier
3) other vendor tables

I need to have the following layout attached.
example_qry.xlsx
sample_3.241.accdb
Avatar of PatHartman
PatHartman
Flag of United States of America image

What is the difference between tbl_spend and tbl_rev?

To make a crosstab from multiple tables, I usually create a select query first to select the columns and join the tables.  Then I use the crosstab wizard to build the crosstab.  The wizard limits you to three Row Heading fields, so just pick the first three.  Then open the query in design view and add the other five.  Make sure you set the Crosstab line to "Row Heading" when you add these columns manually.  The query also allows you to create column header values that the crosstab will use for the "Value" field.
Avatar of kwarden13
kwarden13

ASKER

The database I have been providing is just an example. My actual db has a spend and revenue we are managing for vendors and clients.

Much more complicated. I am using the example to try and build out my actual processes and data. I can create the crosstab but only for spend and then one for revenue. Do I need to do a union to put the data together?
Look at sample (qryCross)
sample_3.241.accdb
Hi als315- How would I create the same for rev and join the two crosstabs?
You never explained rev and spend or why you used two tables rather than one with a type code.
I thought it would be easier since i get certain attributes from a spend system and certain attributes from our revenue system.

Also spend is updated at a separate time then revenue. Not every vendor has revenue and not every client has spend.
ASKER CERTIFIED SOLUTION
Avatar of PatHartman
PatHartman
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
So i have vendors and client names in the same table but separated the revenue and spend. So I wll try to put revenue and spend in the same table.
SOLUTION
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
Hard-coding parameters in queries is poor practice if the parameters can change.  Use a form to run the query and add a control to the form to control the date range.  It is OK to hard-code unchanging stuff.  So for example, if you had a report that you ran that was only ever supposed to include active customers then hard-coding the criteria needed to select "Active" would be fine.  However, if you wanted to use the report for Active, Inactive, or all, then you should make the criteria variable and use a form.  I don't ever rely on prompts since they don't allow for pre-validation which you probably want to do, and you will get prompted at least one more time if you go from print preview to print.
Thanks again, Pat! Good advice on the last bullet and I will keep in mind for the future. For now, I will be combining the clients and vendors into one table as suggested and added a field to identify either.