Question:

I have given up trying to figure out the following problem as it seems over my head, and am
hoping there is a kind soul out there can help me out with the solution.

I am trying to setup a spreadsheet to make calculations which are then exported to Quickbooks.

The original data is returned to Excel from an Access database by msq. Each record relates to an order number and is tied to a

product, and there may be more than entry for each order number as an order may have more than one product.

The actual data import sheet looks something like this:

OrderNumber ItemNumber Date Product PricePerUnit CostPerUnit
4967 1 10-May-10 widget 430.92 306.00
4967 2 10-May-10 doohickey 256.33 165.00
4968 1 11-May-10 doohickey 256.33 165.00

The actual data export sheet looks something like this:

Date Name Account Account Type MEMO Split Account Amount
10-May-10 vendor1 Bank Credit Card 4967 Cost of Goods Sold -306.00
10-May-10 vendor1 Bank Credit Card 4967 Cost of Goods Sold -165.00
11-May-10 vendor2 Bank Credit Card 4968 Cost of Goods Sold -165.00

My problem is that I cannot figure out how to return the total only, and not individual amounts, for orders
with more than 1 item. I.E., how can I tell excel to return each OrderNumber only once, along with
the total for each, like this:

Date Name Account Account Type MEMO Split Account Amount
10-May-10 vendor1 Bank Credit Card 4967 Cost of Goods Sold -471.00
11-May-10 vendor2 Bank Credit Card 4968 Cost of Goods Sold -165.00

There is a little more to this, as I am also trying to include shipping costs, but I Am still trying to
figure out how to return the data using msq, which I am finding a little quirky to use at all, but I have
managed to at least get it to work on a basic level.

Anyhow, is there anyone there who can help? I would be very grateful and much obliged.

AJ

To calculate the total amount for each order number you can create a pivot table. I will also provide a solution using array formula.

### Calculate the total for orders with more than one item with pivot table (Excel 2007)

Create Pivot table

1. Select range A1:H4

2. Click "Insert" tab on the ribbon
3. Click "Pivot table" button
4. Choose where you want the pivot table to be placed

5. Click OK

Setup Pivot table

1. Drag field Date down to "Report Filter" area
2. Drag field MEMO to "Row Labels" area
3. Drag field Amount to "Values" area

Total amount for each unique order number

### Calculate the total for orders with more than one item with excel formula

Array formula in A11:

=INDEX(\$A\$2:\$H\$4, SMALL(IF(MATCH(\$E\$2:\$E\$4, \$E\$2:\$E\$4, 0)=ROW(\$E\$2:\$E\$4)-MIN(ROW(\$E\$2:\$E\$4))+1, ROW(\$E\$2:\$E\$4)-MIN(ROW(\$E\$2:\$E\$4))+1, ""), ROW(A1)), COLUMN(A1)) + CTRL + SHIFT + ENTER.

Copy cell A11 and paste it to the right as far as needed. Then copy the row and paste it down as far as needed.

Formula in H11:

=SUMPRODUCT(--(E11=\$E\$2:\$E\$4), \$H\$2:\$H\$4) + ENTER.

Copy cell H11 and paste it down as far as needed.

Download excel sample file for this tutorial.
pivot table.xlsx
(Excel 2007 Workbook *.xlsx)

INDEX(array,row_num,[column_num])
Returns a value or reference of the cell at the intersection of a particular row and column, in a given range

IF(logical_test;[value_if:true];[value_if_false])
Checks whether a condition is met, and returns one value if TRUE, and another value if FALSE

MIN(number1,[number2])
Returns the smallest number in a set of values. Ignores logical values and text

ROW(reference) returns the rownumber of a reference

SMALL(array,k) Returns the k-th smallest row number in this data set.

SUMPRODUCT(array1, array2, )
Returns the sum of the products of the corresponding ranges or arrays

MATCH(lookup_value;lookup_array; [match_type]
Returns the relative position of an item in an array that matches a specified value

COLUMN(reference)
returns the column number of a reference