Difficult formula? Code? If statement? Help?

afs24

Board Regular
Joined
Sep 26, 2002
Messages
237
I'm trying to write an if statement in the control source section of a report. Unless there is an easier way? Example:

A B Cartons Units (column A X Cartons)

12 6 2 24
6 6 2 12
12 6 3 36
16 8 2 36
12 4 2 24

What would be the formula to pull the percent of all As that equal 12 and B
s that equal 6. Basically, I want everything were column A & B equal 12 and 6 and what that percent of units is to the total units. For this example, rows 1 & 3 equal 12/6 which totals to 60 units. Now that I got the 60 units what percent is 60 units to the total which is 132 (add up all the units in the units column).
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
You'll need 3 fields and a couple of extra queries.

First, go to the original data source -- if it's a query, modify it as below. If a table, create a query from it with the same fields as the original, then make the changes. Let's call this Query1.

After the A B Cartons Units fields, create these:
ATwelve:Iif([A]=12,[A],0)
BSix:Iif(=6,,0)
APlusB:[A]+

Query2: Uses Query1 as the data source but only the 3 new fields to start --
ATwelve, BSix, APlusB
Create a new field -- [ATwelve]+[BSix], called MySum
Now click the Totals button on the query toolbar (the Sigma). In the Totals row for each field, change Group By to Sum. That will give you single-line totals.

Query3: Use Query2 as the source. New field, PercentAB, = SumOfMySum/SumOfAPlusB. Format as a Percent.

You can now use that query in your report.

Note: If you are feeling brave, the query calculations that I described above can be done in the report but they have th potential to get messy.

HTH

Denis
 
Upvote 0

Forum statistics

Threads
1,221,558
Messages
6,160,484
Members
451,651
Latest member
Penapensil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top