OR criteria with DAVERAGE - excel

Given a large number of entries like the following:
type quantity
apple 3
orange 6
pear 2
pear 2
orange 1
...
I know I can create a pull down menu where I can select any type, say 'apple' or 'orange' and get the average quantity for that specific type: to do so, I use daverage where the criteria is a cell with data validation (i.e. whose content is controlled by a pull down menu).
But what I would also like to have in my pull down menu is an entry 'apple or orange' which when selected gives me the average quantity for apple and orange combined.
I know I can use daverage to compute that number but I don't know how to use that in combination with a pull down menu to achieve my final goal so that by simply modifying the content of cell controlled by a pull down menu, I can obtain the average for either orange, or apple, or orange and apple combined. Is there a way?

I'm posting an answer regardless because though not suitable for you it may be suitable for others in a similar (but not identical!) situation:
Including blanks in data validation can have drawbacks but if applied only to the selection criteria (highlighted yellow) this can be advantageous (two blanks in A2:A3 and the overall average is shown). Treating apple and orange separately rather than as orange-apple is simpler (does not require your workaround) and flexible – any pair (rather than pear!) could be chosen without extending the validation list.

Following pnuts' suggestion and the very same example data: I added a column isAppleOrOrange, computing yes or no using a following formula like this:
=IF(OR(A6="apple",A6="orange"),"yes","no")
This way, if you specify 'yes' in B2, you get the average for apple + orange combined. You can still specify any fruit you want in B1 to get the average for a specific fruit alone but need to make sure isAppleOrOrange is left blank in that case:

Related

Is there a way I can count a specific string (Product) in a column times by the neighboring cell (Quantity) so show how much of a product I have sold [duplicate]

I'm wondering if there is an easy way to do what I'm looking for. Basically, I have a balance sheet in Excel 2011 with a bunch of data. One specific piece of information I always want visible is the amount that hasn't been reimbursed. In other words, I have a column for the amount paid and another for whether or not it has been reimbursed (Yes/No). I want to sum all of the amounts paid where the reimbursed field is equal to 'No'.
I recognize I can sum the entire column and filter out those that have been reimbursed, but I'd like it to display the full amount regardless of what filter is on (or if no filter is on).
I wasn't able to find good keywords to describe this to Google, so I'm asking here. I would like to accomplish this in Excel, not in an external program or script.
If column A contains the amounts to be reimbursed, and column B contains the "yes/no" indicating whether the reimbursement has been made, then either of the following will work, though the first option is recommended:
=SUMIF(B:B,"No",A:A)
or
=SUMIFS(A:A,B:B,"No")
Here is an example that will display the amounts paid and outstanding for a small set of sample data.
A B C D
Amount Reimbursed? Total Paid: =SUMIF(B:B,"Yes",A:A)
$100 Yes Total Outstanding: =SUMIF(B:B,"No",A:A)
$200 No
$300 No
$400 Yes
$500 No
You could do this using SUMIF. This allows you to SUM a value in a cell IF a value in another cell meets the specified criteria. Here's an example:
- A B
1 100 YES
2 100 YES
3 100 NO
Using the formula: =SUMIF(B1:B3, "YES", A1:A3), you will get the result of 200.
Here's a screenshot of a working example I just did in Excel:
You should be able to use the IF function for that. the syntax is =IF(condition, value_if_true, value_if_false). To add an extra column with only the non-reimbursed amounts, you would use something like:
=IF(B1="No", A1, 0)
and sum that. There's probably a way to include it in a single cell below the column as well, but off the top of my head I can't think of anything simple.

Excel Sumif, Sumifs with partial strings in multiple columns?

So this is the simplified question I broke down from a former question I had here: Excel help on combination of Index - match and sumifs? .
For this one, I have Table1 (the black-gray one) with two or more columns for adjustments for various order numbers. See this image below:
What I want to achieve is to have total adjustments for those order numbers that contain the numbers in Total Adjustment column in the blue table, each of which will depend on the cell beside it.
Example: Order number 17051 has two products: 17051A (Apple) and 17051B (Orange).
Now what I want to achieve in cell C10 is the sum of adjustment for both 17051A and 17051B, which will be: Apple Adjustment (5000) + Orange Adjustment (4500) = 9500.
The formula I used below (and in the image) kept giving me error messages, and this happens even before I add the adjustment for Orange.
=SUMIF(Text(LEFT(Table1[Order Number],5),"00000"),text(B10,"00000"),Table1[Apple Adjustment])
I have spent the whole day looking for a solution for this and didn’t even come close to find any. Any suggestion is appreciated.
Assuming your headers always have the text "adjustment" in them, you could use:
=SUMPRODUCT((LEFT($B$4:$B$7,5)=B10&"")*(RIGHT($C$3:$F$3,10)="adjustment")*$C$4:$F$7)
In C10 you could add two sumproducts. This assumes that products are always 5 numbers long at the start. If not swop the 5 to use the length of the product reference part you are matching on.
=SUMPRODUCT(--(1*LEFT($B$4:$B$7,5)=$B10),$D$4:$D$7)+SUMPRODUCT(--(1*LEFT($B$4:$B$7,5)=$B10),$F$4:$F$7)
Which with table syntax is:
=SUMPRODUCT(--(1*LEFT(Table1[Order Number],5)=$B10),Table1[Apple Adjustment])+SUMPRODUCT(--(1*LEFT(Table1[Order Number],5)=$B10),Table1[Orange Adjustment])
Using LEN
=SUMPRODUCT(--(1*LEFT(Table1[Order Number],LEN($B10))=$B10),Table1[Apple Adjustment])+SUMPRODUCT(--(1*LEFT(Table1[Order Number],LEN($B10))=$B10),Table1[Orange Adjustment])
I am multiplying by 1 to ensure Left, 5 becomes numeric.

Subtract two range values for matching ones excel

I have come across of the problem that, I don't know how to solve in efficient way. So I have two tables like these:
Table 1
Company Score
Apple 10
Banana 5
Kiwi 4
Pineapple 2
Table 2
Company Score
Apple 4
Pineapple 3
Kiwi 2
Strawberry 1
Then in my result table in which I have company names listed in one column, like below. Right next to this I would like to show the differences which should be the first table values - the second table values where company names match(the list can be in different order that is why, I need to check it before subtracting).
Table 3
Company Result
Kiwi 2
Apple 6
Banana -5
Pineapple -1
I can do this with nested IF function to check every cell one by one, but I assume there might be more efficient way. I wonder if you have one.
Thanks to #ScottCraner's comment, I solved it with two sumifs subtracted from one another with this formula. I entered this in Column D66 and dragged down
=SUMIF($C$36:$C$45;$C$66:$C$75;D$36:D$45)-SUMIF($C$51:$C$60;$C$66:$C$75;D$51:D$60)
1st Sum if: Where C36-C45 is my first list of companies, C66-C75 is the list of companies that I have in the results table, D36 -D45 is the score list from the first table.
2nd Sum if: Where C51-C60 is my second list of companies, C66-C75 is the list of companies that I have in the results table, D51 -D60 is the score list from the second table.

Calculate column value by sub-column value

I know this will require an advanced custom expression - I have 2 relevant columns, commodity and sub-commodity. A single event can have multiple commodities and sub-commodities. However, some commodities will naturally have more data about them. I don't want this to skew representation of the data.
I want to avoid that by counting values by their unique sub-commodity. In the below example, I want the bar chart to represent two instances of food for Event 1 (1 for meat, 1 for beverages) and one instance of garden for Event 2. How do I accomplish this?
EventID | Commodity | Sub-Commodity
1 Food Meat
1 Food Meat
1 Food Beverages
2 Garden Lawn Mower
2 Garden Lawn Mower
Thanks for the sample data. It helps in providing an answer.
You should be able to do this by using the UniqueCount() function. In this case the Y axis would be the expression UniqueCount([Sub-Commodity]). You can use custom expressions to input this or use the built-in drop down and select UniqueCount from the aggregation drop-down.
Take a look at the below image showing my implementation with a custom expression. Coloring is optional but I did so to show how it included your multiple sub-commodities and how they were counted (1 for Food=>Meat).
See below for an example with the drop-down:
Let me know if you have any questions or need further clarification. Thanks!

How should I design an data table that has six or more variables?

The situation is akin to the following:
Assume I am a store selling fruits, I would like to record the costs of each type of fruit. Assume the customer has specific tastes, and they can differentiate everything.
A fruit can be an orange, apple,
pear, or peach
It could be n days fresh from the vendor
The fruits come from different countries and have different taxes for export
Fruits are also valued by weight
Fruits could have handling requirements (Fridge,water sprigs)
Fruits could also be valued just because of different origins
One idea is to do what is done in some industries, assign a unique product code for each variation: e.g. Orange5dayfreshAustralia200gfridgeSydney
This however, would be a HUUUUUGE long list of values, and should any costs change, it would be hell to search for Apples from Turkey that are 200 grams have now 20cents more export tax. Adding new variables would also massively mess up the whole table and require much recoding.
The other way is to assume a standard orange, peach, apple and pear and different weight(2 dimensional table). On other tables, prepare a list of cost savings/increase for any given deviation. (Law of probability should show me I have 80% "standard" fruits, and 20% niche fruits from funky places having funky costs)
E.g. a 1 day fresh orange compared to a standard 4 day fresh orange is 50cents more, regardless of weight.
(Yes, this means the primary table would need to have at least one variable that dont affect the others)
Final constrain: The data entry is done by hired hands, needs to be simple to enter in Excel. The programing can be difficult, but not the general interface.
Any suggestions?
If the information needs to be encoded in the product code, you can use subcodes to build a complete product code.
Type of fruit
AP - Apple
OR - Orange
PR - Pear
PC - Peach
You can use Country Codes for the country, and other subcodes for handling and origin.
EXAMPLE:
AP06BR145HROR
is a Brazilian apple, six days old, weighing 145 grams, with HR handling and OR origins.
Obviously you would need a lookup table and foreign keys for each of the code types.
You seem to have twigged your problem - your data structure is wrong.
Your list is really a collection of attributes that apply to each "batch" of stock you purchase - except perhaps for "n days fresh" where the attribute is the difference between the attributes of date picked and date delivered.
So what you really want is a data table for each attribute type, and then a transcation data table where you add the attributes. The input is a form where the attributes are loopups.
You also need your pricing rules in a table, which you can use to calculate prices.
If your transaction table records both sales and purchases then you can filter on the attributes to report by any combination you like.
But the bit that interests me is how you work out how old the fruit is you are selling. You might know from the paperwork that you have purchased x oranges from Spain on one day and y oranges from Italy on another day, but in the box oranges are just oranges - so how do you tell which are which? Or are you planning to use a FIFO or LIFO scheme?

Resources