creating queries to show budgeted vs. actual costs€¦ · creating queries to show budgeted vs....

14
CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS The first Query is going to be sourced from multiple tables: Job_budgets : This table houses the Job_id, Cost_code_id and estimated Costs per cost code and cost class. (Basically, all information on the Job Budget tab) Job_costcodes : This table houses the information on the left hand side of the Budget Tab. We use this table in case the Cost Code Description has been changed on the Budget Tab from the default cost code description under Cost Code Maintenance. Jobs : This table houses the Job Description Cost_Classes : This table houses the Cost Class Description

Upload: vungoc

Post on 20-Apr-2018

225 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS€¦ · CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS The first Query is going to be sourced from multiple tables: Job_budgets

CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS The first Query is going to be sourced from multiple tables: Job_budgets : This table houses the Job_id, Cost_code_id and estimated Costs per cost code

and cost class. (Basically, all information on the Job Budget tab) Job_costcodes : This table houses the information on the left hand side of the Budget Tab. We

use this table in case the Cost Code Description has been changed on the Budget Tab from the default cost code description under Cost Code Maintenance. Jobs : This table houses the Job Description Cost_Classes : This table houses the Cost Class Description

Page 2: CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS€¦ · CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS The first Query is going to be sourced from multiple tables: Job_budgets

Links, links, links. The links are VERY important in this query, as each table can relate to others. Since the JOB_BUDGTS table is the “source” table we need to remove any links that do not apply. Here are the links that should remain in the query: JOB_BUDGETS to JOB_COSTCODES should be linked via cost_code_no, job_no and

phase_no JOB_BUDGETS to JOBS should be linked via job_no JOB_BUDGETS to COST_CLASSES should be linked via cost_class_no We will also create associated / concatenated fields to represent the Job Number – Description,

Cost Code Number – Description and the Cost Class Number – Description: job_budgets.job_id+' - '+jobs.description job_budgets.cost_code_id+' - '+job_costcodes.description job_budgets.cost_class_id+' - '+cost_classes.description We will maintain the fields with the job_id, cost_code_id and cost_class_id as separate fields

(more on this later)

Rename the column headings for these items:

Page 3: CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS€¦ · CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS The first Query is going to be sourced from multiple tables: Job_budgets

Return the data to Excel and rename the sheet “BUDGET”:

We will begin a new query to pull in the Change Order Costs:

This query will use two tables: job_chg_budgets and job_chg Since we have the detailed Descriptions on the information on the BUDGETS query, we only need to pull the items that we are using for reference back to that table. In this case, the JOB_ID, the COST_CODE_ID and the COST_CLASS_ID. We then need the cost_adj and the unit_adj fields for the values that are being updated with the change order. The job_chg table is the header record (or the general tab) of the Change Order. This table is pulled simply to limit the change orders by the status of A for Approved and E for Estimate.

Page 4: CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS€¦ · CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS The first Query is going to be sourced from multiple tables: Job_budgets

Return the Data to Excel and Rename the Sheet “CO”:

Now fun begins… we want to associate the values on the CO (Change Order) sheet to the similar

job/cost code/cost class items on the BUDGETS tab. We will use the SUMIFS function to accomplish this. Basically the SUMIFS Formula says, “return a value from a defined range when multiple criteria

are met.” In this case, we want to look at the job/cost code/cost class combination on the BUDGET tab, find and sum the related Change Order adjustments on the CO sheet when the job/cost code/cost class reference is the same between the two sheets.

Page 5: CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS€¦ · CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS The first Query is going to be sourced from multiple tables: Job_budgets

The SUMIFS Formula is written as follows: =SUMIF(SUM_RANGE,CRITERIA_1 RANGE,CRITERIA1,CRITERIA_2 RANGE,CRITERIA2) We will be using 3 distinct criteria in our sumifs statement, although up to 127 are allowed. Here is the creation of the SUMIFS statement based on our existing query: I have created a new column named CO_COST

The first part of the Formula is to define the SUM_RANGE, in other words, where should the

formula look to gather the values ? In this case, the sum_range will be all of the data in the cost_adj column (column D) on the CO sheet.

Page 6: CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS€¦ · CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS The first Query is going to be sourced from multiple tables: Job_budgets

The CRITERIA_RANGE1 will be all values in the JOB_ID column (column A) on the CO sheet.

The CRITERIA1 value will be pulled from the BUDGET sheet. This is the value in Cell A2 from

the JOB_ID column. Remember that this is the first of 3 criteria that we are making reference.

Page 7: CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS€¦ · CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS The first Query is going to be sourced from multiple tables: Job_budgets

Back to the CO sheet for CRITERIA_RANGE2. The second criteria range will be all values in the

cost_code_id column (Column B).

The Value for Criteria2 will be pulled from the cost_code_id field on the BUDGETS tab.

So far we have told the equation to match the values for the JOB_ID and COST_CODE_ID. The

last criteria in the formula will be to match the cost_class_id.

Page 8: CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS€¦ · CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS The first Query is going to be sourced from multiple tables: Job_budgets

Back to the CO sheet, and select all values in the cost_class_id column (column C)

Finally, we will define the Criteria3 value as the value in cell E2 from the BUDGET sheet.

Close parenthesis on the formula, cross your fingers, and let’s review the results.

Page 9: CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS€¦ · CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS The first Query is going to be sourced from multiple tables: Job_budgets

On the BUDGETS sheet, we now have a value in the first row of $660. This is the value from the

CO sheet that meets all three of our criteria, same job_id, same cost_code_id and same cost_class_id.

If we would make a change to the Cost Class on line 2 of the CO sheet, you will notice that it

changes the value on the BUDGETS sheet: Original: Change to: New Result for the First Row:

Page 10: CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS€¦ · CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS The first Query is going to be sourced from multiple tables: Job_budgets

Use the same Logic to Produce the Change Orders to the UNITS. You may wish to re-write the

entire SUMIFS formula for the units, but if you look at the equation, it is the same criteria, just a different SUM_RANGE. =SUMIFS(CO!D:D,CO!A:A,BUDGET!A2,CO!B:B,BUDGET!C2,CO!C:C,BUDGET!E2) Instead of SUMMING the values in column D:D form the CO tab, we need to sum the values in

Column E:E (the values in the unit_adj column)

If you simply copy the formula from the formula bar and paste the formula into the adjacent

column, you may then make the necessary edit to re-sum by column E:E. Highlight the Formula in Cell M2 the Formula bar, right click and select COPY.

VERY IMPORTANT:

Page 11: CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS€¦ · CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS The first Query is going to be sourced from multiple tables: Job_budgets

Click the CHECKMARK after you have copied the formula. Remember, you are in the formula

toolbar, if you click anywhere else, it will overwrite your existing formula.

CLICK THIS CHECKMARK BEFORE YOU PROCEED. Select Cell N2,.

click in the Formula Toolbar and Right-Click and Paste

Change D:D to E:E….

We now have the amount(s) from the CO_UNITS column by job, cost code and cost class.

Page 12: CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS€¦ · CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS The first Query is going to be sourced from multiple tables: Job_budgets

Add two more columns for Revised Cost and Revised Units. These are simple additions of your

original_est_dollars + co_cost and the original_est_units and the co_units.

As a final query, we will pull in the actual costs to date for with the same criteria. Access another query using the V_JOB_HISTORY table. Pull in the following fields: job_id, cost_code_id, cost_class_id, cost and units. I have also used

the SUM function on the cost and units fields.

Return the data to Excel and rename the Sheet COST.

Page 13: CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS€¦ · CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS The first Query is going to be sourced from multiple tables: Job_budgets

Perform the SUMIFS equations on the BUDGET sheet in columns Q for Cost: =SUMIFS(COST!D:D,COST!A:A,BUDGET!A2,COST!B:B,BUDGET!C2,COST!C:C,BUDGET!E2)

And R for UNITS: =SUMIFS(COST!E:E,COST!A:A,BUDGET!A2,COST!B:B,BUDGET!C2,COST!C:C,BUDGET!E2)

Page 14: CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS€¦ · CREATING QUERIES TO SHOW BUDGETED VS. ACTUAL COSTS The first Query is going to be sourced from multiple tables: Job_budgets

Once the BUDGETS table is complete, create a Pivot Table based on the available data.